-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfmath2.f95
2514 lines (1966 loc) · 81 KB
/
fmath2.f95
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
!> =============================================================================
!>
!> fmath2.f95 - Astrophysics.
!>
!> =============================================================================
!>
!> Copyright (C) 2018 - 2020 Pablo Edronkin (pablo.edronkin at yahoo.com)
!>
!> This program is free software: you can redistribute it and/or modify
!> it under the terms of the GNU Lesser General Public License as published
!> by the Free Software Foundation, either version 3 of the License, or
!> (at your option) any later version.
!>
!> This program is distributed in the hope that it will be useful,
!> but WITHOUT ANY WARRANTY; without even the implied warranty of
!> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
!> GNU Lesser General Public License for more details.
!>
!> You should have received a copy of the GNU Lesser General Public License
!> along with this program. If not, see <https://www.gnu.org/licenses/>.
!>
!> =============================================================================
!>
!> Sources:
!> - http://annefou.github.io/Fortran/modules/modules.html
!> - https://en.wikipedia.org/wiki/List_of_algorithms
!>
!> Compilation:
!> - ./cfmath.sh or
!> - mpif90 -std='gnu' -c fmath2.f95 -O3 -march=native -Wall -Wextra -fopenmp
!>
module fmath2
use fmath4
use fmath3
implicit none
! Setting a platform-independent floating point precision.
integer, parameter :: fmath2_p1 = selected_real_kind( 10,300 )
!------------------------------------------------------------------------------
contains
!> Calculates angular momentum based on the propotionality of the moment
!> of inertia and angular velocity.
!>
!> Arguments:
!> - p_i: Moment of inertia.
!> - p_w: Angular velocity.
!>
!> Output:
!> - Angular momentum.
!>
!> Sources:
!> - https://en.wikipedia.org/wiki/Angular_momentum
!>
pure real( kind = fmath2_p1 ) function RspFAngularMomentum1( p_i, p_w )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_i, p_w
RspFAngularMomentum1 = p_i * p_w
return
end function
!> Calculates angular momentum based on tangential speed; Tangential speed is considered
!> as equivalent to speed in linear momentum.
!>
!> Arguments:
!> - p_r: Radius of rotation.
!> - p_m: Mass.
!> - p_v: Tangential speed at radius p_r.
!>
!> Output:
!> - Angular momentum.
!>
!> Sources:
!> - https://en.wikipedia.org/wiki/Angular_momentum
!>
pure real( kind = fmath2_p1 ) function RspFAngularMomentum2( p_r, p_m, p_v )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_r, p_m, p_v
RspFAngularMomentum2 = p_r * RspFLinearMomentum1( p_m, p_v )
return
end function
!> Calculates linear momentum taking into account the Lorentz factor. Will cause a divide by
!> zero error at p_v = c .
!>
!> Arguments:
!> - p_m: Rest mass.
!> - p_v: Velocity at the center of mass.
!>
!> Output:
!> - Linear momentum.
!>
!> Sources:
!> - https://en.wikipedia.org/wiki/Momentum
!>
pure real( kind = fmath2_p1 ) function RspFLinearMomentum1( p_m, p_v )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_m, p_v
RspFLinearMomentum1 = p_m * p_v * RspFLorentzFactor( p_v )
return
end function
!> Calculates the Lorentz factor.
!>
!> Arguments:
!> - p_v_km: relative velocity between intertial frames of reference, in kms/s.
!>
!> Returns:
!> - G: Gamma, which is the Lorentz factor.
!>
!> Sources:
!> - https://en.wikipedia.org/wiki/Lorentz_factor
!>
pure real( kind = fmath2_p1 ) function RspFLorentzFactor( p_v_km )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_v_km
RspFLorentzFactor = 1 / sqrt( ( 1 - ( ( RspFBetaVelocity( p_v_km ) )**2 ) ) )
return
end function
!> Calculates the ratio between a given velocity and the speed of light in the vacuum.
!>
!> Arguments:
!> - p_v_km: velocity, in km/s.
!>
!> Output:
!> - b: beta velocity.
!>
!> Sources:
!> - https://en.wikipedia.org/wiki/Beta_(velocity)
!>
pure real( kind = fmath2_p1 ) function RspFBetaVelocity( p_v_km )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_v_km
RspFBetaVelocity = p_v_km / RspFConst("c")
return
end function
!> Calculates the eccentricity of an elliptical galaxy or similar body.
!>
!> Arguments:
!> - p_axis_a_ps: Semi major axis (a) in parsecs.
!> - p_axis_b_ps: Semi minor axis (b) in parsecs.
!>
!> Output:
!> - Eccentricity.
!>
pure real( kind = fmath2_p1 ) function RspFApparentEllipticity( p_axis_a_ps, p_axis_b_ps )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_axis_a_ps, p_axis_b_ps
RspFApparentEllipticity = 1 - ( p_axis_b_ps / p_axis_a_ps )
return
end function
!> Calculates the apparent recessional velocity of a redshifted galaxy.
!>
!> Arguments:
!> - p_z: cosmological redshift.
!> - p_c: speed of light.
!>
!> Output:
!> - ARV.
!>
pure real( kind = fmath2_p1 ) function RspFApparentRecessionalVelocity( p_z, p_c )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_z, p_c
RspFApparentRecessionalVelocity = p_z * p_c
return
end function
!> Calculates the approximate distance L from a body with mass p_mass2_kg at which Lagrange
!> points L1 and L2 are located by calculating its Hill radius assuming a negligible
!> eccentricity.
!>
!> Arguments:
!> - p_mass_m1_kg: mass of the bigger (more massive) body of the system.
!> - p_mass_m2_kg: mass of the lesser body.
!> - p_a: semi major axis of the orbit of object 1 around object 2. Can use any unit of
!> length. The result will be expressed in those units.
!>
!> Output:
!> - Radius at which points L1 and L2 are located (separated 180 degrees) on the line between
!> bodies with masses p_mass_m1 and p_mass_m2 according to this general distribution (not to
!> scale):
!>
!> (L4)
!>
!>
!>
!> (L3) --------- (M1) --------- (L1) --- (M2) --- (L2)
!>
!>
!>
!> (L5)
!>
!> Sources:
!> - https://en.wikipedia.org/wiki/Lagrangian_point
!>
!> NEEDS TESTING
!>
pure real( kind = fmath2_p1 ) function RspFApproximateLagrangianL1L2( p_mass1_kg, p_mass2_kg, p_a )
implicit none
real( kind = fmath2_p1 ) :: b
real( kind = fmath2_p1 ), intent(in) :: p_mass1_kg, p_mass2_kg, p_a
b = 0.0
RspFApproximateLagrangianL1L2 = RspFHillSphere(p_mass1_kg, p_mass2_kg, b, p_a);
return
end function
!> Calculates the approximate distance L from a body with mass p_mass2_kg at which Lagrange point L3
!> is located by calculating its Hill radius assuming a negligible eccentricity.
!>
!> Arguments:
!> - p_mass_m1_kg: Mass of the bigger (more massive) body of the system.
!> - p_mass_m2_kg: Mass of the lesser body.
!> - p_a: Semi major axis of the orbit of object 1 around object 2. Can use any unit of
!> length. The result will be expressed in those units.
!>
!> Output:
!> - Radius at which points L3 is located according to this general distribution (not to scale):
!>
!> (L4)
!>
!>
!>
!> (L3) --------- (M1) --------- (L1) --- (M2) --- (L2)
!>
!>
!>
!> (L5)
!>
!> Sources:
!> - https://en.wikipedia.org/wiki/Lagrangian_point
!>
!> NEEDS TESTING
!>
pure real( kind = fmath2_p1 ) function RspFApproximateLagrangianL3( p_mass1_kg, p_mass2_kg, p_a )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_mass1_kg, p_mass2_kg, p_a
RspFApproximateLagrangianL3 = p_a * ( 2 * ( 5 * p_mass2_kg ) / ( 1 * p_mass1_kg ))
return
end function
!> Finds out if Lagrangian points L3 or L4 in a system of two orbiting massive bodies are
!> stable or not depending on the ratio between both masses, which has to be greather than
!> the predefined stability limit sl.
!>
!> Arguments:
!> - p_mass1: mass of the main body of the system.
!> - p_mass2: mass of the satellite.
!>
!> Output:
!> - 1.0 (true) if L3 and L4 are stable, 0.0 (false) otherwise.
!>
!> Sources:
!> - https://en.wikipedia.org/wiki/Lagrangian_point
!>
pure real( kind = fmath2_p1 ) function RspFAreLagrangianPointsL3L4Stable( p_mass1, p_mass2 )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_mass1, p_mass2
if ( RspFMassRatio( p_mass1, p_mass2 ) > RspFConst("sl") ) then
RspFAreLagrangianPointsL3L4Stable = 1.0
else
RspFAreLagrangianPointsL3L4Stable = 0.0
end if
return
end function
!> Calculates the ratio between two masses.
!>
!> Arguments:
!> - p_mass1: Primary mass.
!> - p_mass2: Secondary mass.
!>
!> Output:
!> - Ratio between both masses.
!>
pure real( kind = fmath2_p1 ) function RspFMassRatio( p_mass1, p_mass2 )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_mass1, p_mass2
RspFMassRatio = p_mass1 / p_mass2
return
end function
!> Approximates the Roche lobe as a sphere of the same volume using the Eggleton formula.
!>
!> Arguments:
!> - p_mass1: mass of the major body.
!> - p_mass2: mass of the minor body.
!> - p_a: orbital separation of the system.
!>
!> Output:
!> - Approximate radius of the sphere of same volume as the Roche radius.
!>
!> Sources:
!> - https://en.wikipedia.org/wiki/Roche_lobe
!> - http://cronodon.com/SpaceTech/Roche_Potential.html
!>
!> NEEDS TESTING.
!>
pure real( kind = fmath2_p1 ) function RspFApproximateRocheLobeEggleton( p_mass1, p_mass2, p_a )
implicit none
real( kind = fmath2_p1 ) :: b, q1, q2
real( kind = fmath2_p1 ), intent(in) :: p_mass1, p_mass2, p_a
q1 = p_mass1 / p_mass2
q2 = q1**( 2 / 3 )
b = 3.0
RspFApproximateRocheLobeEggleton = p_a * ( (0.49 * q2 ) / ( ( 0.6 * q2 ) + log( 1 + RspFNthroot( q1 , b ) ) ) )
return
end function
!> Calculates an approxiamte value for the radius of the Hill sphere of an object of p_mass2_kg
!> orbiting around an object of p_mass1_kg.
!>
!> Arguments:
!> - p_mass1_kg: mass of the bigger (more massive) body of the system.
!> - p_mass2_kg: mass of the lesser body.
!> - p_e: eccentricity of the orbit.
!> - p_a: semi major axis of the orbit of object 1 around object 2. Can use any unit of
!> length. The result will be expressed in those units.
!>
!> Output:
!> - Approximated radius of the Hill sphere around the lesser body.
!>
!> Sources:
!> - https://en.wikipedia.org/wiki/Hill_sphere
!> - https://en.wikipedia.org/wiki/Roche_lobe
!> - https://en.wikipedia.org/wiki/Roche_limit
!>
!> NEEDS TESTING
!>
pure real( kind = fmath2_p1 ) function RspFHillSphere( p_mass1_kg, p_mass2_kg, p_e, p_a )
implicit none
real( kind = fmath2_p1 ) :: b
real( kind = fmath2_p1 ), intent(in) :: p_mass1_kg, p_mass2_kg, p_e, p_a
b = 3.0
RspFHillSphere = p_a * ( 1 - p_e ) * RspFNthroot( ( p_mass2_kg / ( 3 * p_mass1_kg ) ), b )
return
end function
!> Returns the distance in km of an object.
!>
!> Arguments:
!> - p_parallax: Parallax measured in arcseconds.
!>
!> Output:
!> - Distance to the object, measured in km.
!>
pure real( kind = fmath2_p1 ) function RspFArcsec2Km( p_parallax )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_parallax
RspFArcsec2Km = RspFPs2Km( RspFArcsec2Ps( p_parallax ) );
return
end function
!> pe_arcsec_to_ps (p_parallax) returns the distance in parsecs of an object.
!>
!> Arguments:
!> - p_parallax: Parallax, in arcseconds.
!>
!> Output:
!> - Distance to the object, expressed in parsecs.
!>
pure real( kind = fmath2_p1 ) function RspFArcsec2Ps( p_parallax )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_parallax
RspFArcsec2Ps = 1 / p_parallax;
return
end function
!> Converts a distance expressed in parsecs to kilometers.
!>
!> Arguments:
!> - p_distance_in_ps: Distance to the target, in parsecs.
!>
!> Output:
!> - Distance to the target expressed in kilometers.
!>
pure real( kind = fmath2_p1 ) function RspFPs2Km( p_distance_in_ps )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_distance_in_ps
RspFPs2Km = RspFOther2Km( p_distance_in_ps, RspFConst("pk") )
return
end function
!> Converts a distance expressed in other units of longitude or distance to kilometres.
!>
!> Arguments:
!> - p_distance_in_other: distance expressed in other measure.
!> - p_otherinkm: other distance expressed in km.
!>
!> Output:
!> - Distance in km.
!>
pure real( kind = fmath2_p1 ) function RspFOther2Km( p_distance_in_other, p_otherinkm )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_distance_in_other, p_otherinkm
RspFOther2Km = p_distance_in_other * p_otherinkm
return
end function
!> Returns the distance in light years of an object.
!>
!> Arguments:
!> - p_parallax: Parallax, in arcseconds.
!>
!> Output:
!> - Distance to the object, expressed in light years.
!>
pure real( kind = fmath2_p1 ) function RspFArcsec2Ly( p_parallax )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_parallax
RspFArcsec2Ly = RspFKm2Ly( RspFArcsec2Km( p_parallax ) )
return
end function
!> Converts a distance expressed in km to light years.
!>
!> Arguments:
!> - p_distance_in_km: Distance to the target expressed in km.
!>
!> Output:
!> - Distance in light years.
!>
pure real( kind = fmath2_p1 ) function RspFKm2Ly( p_distance_in_km )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_distance_in_km
RspFKm2Ly = RspFKm2Other( p_distance_in_km, ( RspFConst("sy") * RspFConst("c") ) )
return
end function
!> Converts a distance expressed in km to another unit of measure or distance.
!>
!> Arguments:
!> - p_distance_in_km: Distance to the target expressed in km.
!> - P_otherinkm: Selected unit of length or distance expressed in km.
!>
!> Output:
!> - Distance to the target in the selected unit of length.
!>
pure real( kind = fmath2_p1 ) function RspFKm2Other( p_distance_in_km, p_otherinkm )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_distance_in_km, p_otherinkm
RspFKm2Other = p_distance_in_km / p_otherinkm
return
end function
!> Returns the astronomical (geometric) albedo of a celestial body.
!>
!> Arguments:
!> - p_absolute_magnitude: absolute magnitude of CB.
!> - p_diameter_km: diameter of the CB, in km.
!>
!> Output:
!> - Albedo of CB.
!>
!> Sources:
!> - [1] https://en.wikipedia.org/wiki/Albedo
!>
!> NEEDS TESTING
!>
pure real( kind = fmath2_p1 ) function RspFAstronomicalAlbedo( p_absolute_magnitude, p_diameter_km )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_absolute_magnitude, p_diameter_km
RspFAstronomicalAlbedo = ( ( 1329.0 * (10.0 ** ( ( (-1.0) * p_absolute_magnitude ) / 5.0 ) ) ) / p_diameter_km )**2.0;
return
end function
!> Converts a distance expressed in AU to kilometres.
!>
!> Arguments:
!> - p_distance_in_au: Distance measured in astronomical units.
!>
!> Output:
!> - Distance expressed in kilometers.
!>
pure real( kind = fmath2_p1 ) function RspFAu2Km( p_distance_in_au )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_distance_in_au
RspFAu2Km = RspFOther2Km( p_distance_in_au, RspFConst("ak") )
return
end function
!> Calculates the Semi-major axis of the primary's orbit arbarycenter of the system based
!> on the distance between the centers ofound the two masses and the values of those masses.
!>
!> Arguments:
!> - p_a: distance between the centers of the two bodies (semi major axis of the system).
!> - p_mass1: Mass of the first body.
!> - p_mass2: Mass of the second body.
!>
!> Output:
!> - Semi-major axis of the primary's orbit around the barycenter.
!>
!> Sources:
!> - https://en.wikipedia.org/wiki/Barycenter
!>
pure real( kind = fmath2_p1 ) function RspFBarycenter( p_a, p_mass1, p_mass2 )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_a, p_mass1, p_mass2
RspFBarycenter = p_a * RspFRatioBeta (p_mass1, p_mass2)
return
end function
!> Finds the result of a = p_q1 / (p_q1 + p_q2).
!>
!> Arguments:
!> - p_q1
!> - p_q1
!>
!> Output:
!> - Ratio alpha.
!>
pure real( kind = fmath2_p1 ) function RspFRatioAlpha( p_q1, p_q2 )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_q1, p_q2
RspFRatioAlpha = p_q1 / (p_q1 + p_q2)
return
end function
!> Finds the result of b = p_q2 / (p_q1 + p_q2)
!>
!> Arguments:
!> - p_q1
!> - p_q2
!>
!> Output:
!> - b.
!>
pure real( kind = fmath2_p1 ) function RspFRatioBeta( p_q1, p_q2 )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_q1, p_q2
RspFRatioBeta = p_q2 / ( p_q1 + p_q2 )
return
end function
!> Calculates data for a simple model of the black body.
!>
!> Arguments:
!> - p_t: T in Kelvin units.
!> - p_w: wavelength [0.01:0.01:5.0] microns sweep over a range of wavelengths.
!>
!> Output:
!> - Result in W/m2/um x 1E8 .
!>
!> Sources:
!> - MATLAB/Octave/Freemat
!>
pure real( kind = fmath2_p1 ) function RspFBlackBodySimpleModel( p_t, p_w )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_t, p_w
RspFBlackBodySimpleModel = 3.742 / ( ( p_w**5 ) * ( exp( 1.439E4 / ( p_w * p_t ) ) * ( -1.0 ) ) )
return
end function
!> Returns the distance in parsecs to a star using the distance modulus m - M as a parameter.
!> This version of the equation requires the user to enter the result of the rest between
!> apparent and absolute magnitudes.
!>
!> Arguments:
!> - p_distance_modulus: value of the difference between apparent and absolute magnitudes.
!>
!> Output:
!> - Distance expressed in parsecs.
!>
!> Sources:
!> -
!>
pure real( kind = fmath2_p1 ) function RspFDm2Ps( p_distance_modulus )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_distance_modulus
RspFDm2Ps = 10**( ( p_distance_modulus / 5 ) + 1 )
return
end function
!> Calculates the Doppler factor of a source relative to the observer.
!>
!> Arguments:
!> - p_v: Velocity, needed to calculate the beta velocity or speed of an object relative
!> to the speed of light, in km/s.
!>
!> Output:
!> - Ratio fs/fo
!>
!> Sources:
!> - https://en.wikipedia.org/wiki/Relativistic_Doppler_effect
!> - https://en.wikipedia.org/wiki/Beta_(velocity)
!> - https://en.wikipedia.org/wiki/Hubble%27s_law
!>
pure real( kind = fmath2_p1 ) function RspFDopplerFactor( p_v )
implicit none
real( kind = fmath2_p1 ) :: beta
real( kind = fmath2_p1 ), intent(in) :: p_v
beta = RspFBetaVelocity( p_v )
RspFDopplerFactor = sqrt( ( ( 1 + beta ) / ( 1 - beta ) ) )
return
end function
!> Estimates the number of probable civilizations in our galaxy that might have a sufficient
!> degree of technology that would allow them to communicate. In other words, it guesses how
!> many people we might call to chat in our place in the universe. This is the original form
!> of the Drake equation.
!>
!> Arguments:
!> - p_r: average rate of star formation in the galaxy, per year.
!> - p_fo: fraction of star systems with planets.
!> - p_ne: average number of life-supporting planets per system in those systems with planets.
!> - p_fl: fraction of those p_ne planets that actually develop life.
!> - p_fi: fraction of those P_fl planets that develop civilizations.
!> - p_fc: fraction of hose p_fi civilizations that developed communications technologies.
!> - p_l: length of time, in years over which such civilizations broadcast their messages.
!>
!> Output:
!> - Number of probable communicative civilizations in the Milky Way.
!>
!> Sources:
!> - https://en.wikipedia.org/wiki/Drake_equation
!>
pure real( kind = fmath2_p1 ) function RspFDrakeEquation1( p_r, p_fo, p_ne, p_fl, p_fi, p_fc, p_l )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_r, p_fo, p_ne, p_fl, p_fi, p_fc, p_l
RspFDrakeEquation1 = p_r * p_fo * p_ne * p_fl * p_fi * p_fc * p_l
return
end function
!> Estimates the number of probable civilizations in our galaxy that might have a sufficient
!> degree of technology that would allow them to communicate. In other words, it guesses how
!> many people we might call to chat in our place in the universe. This is the Jul 2013
!> Popular Science variant of the Drake equation that includes the Dalek variable.
!>
!> Arguments:
!> - p_r: average rate of star formation in the galaxy, per year.
!> - p_fo: fraction of star systems with planets.
!> - p_ne: average number of life-supporting planets per system in those systems with planets.
!> - p_fl: fraction of those p_ne planets that actually develop life.
!> - p_fi: fraction of those P_fl planets that develop civilizations.
!> - p_fc: fraction of hose p_fi civilizations that developed communications technologies.
!> - p_l: length of time, in years over which such civilizations broadcast their messages.
!> - p_fd: Dalek factor. Number of civilizations that can survive an alien attack.
!>
!> Output:
!> - Number of probable communicative civilizations in the Milky Way.
!>
!> Sources:
!> - https://en.wikipedia.org/wiki/Drake_equation
!>
pure real( kind = fmath2_p1 ) function RspFDrakeEquation2( p_r, p_fo, p_ne, p_fl, p_fi, p_fc, p_l, p_fd )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_r, p_fo, p_ne, p_fl, p_fi, p_fc, p_l, p_fd
RspFDrakeEquation2 = p_r * p_fo * p_ne * p_fl * p_fi * p_fc * p_l * p_fd
return
end function
!> Equation of state of a perfect fluid.
!>
!> Arguments:
!> - p_pressure: Force applied perpendicularly to a surface per unit area, expressed in
!> kg / (m * s**2).
!> - p_energy_density: amount of energy stored in a given system or region of space per
!> unit volume or mass, expressed in kg / (m * s**2).
!>
!> Output
!> - Dimentionless ratio.
!>
!> Sources:
!> - [1] https://en.wikipedia.org/wiki/Equation_of_state_(cosmology)
!> - [2] https://en.wikipedia.org/wiki/Pressure
!> - [3] https://en.wikipedia.org/wiki/Energy_density
!>
pure real( kind = fmath2_p1 ) function RspFStateEquation( p_pressure, p_energy_density )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_pressure, p_energy_density
RspFStateEquation = p_pressure / p_energy_density
return
end function
!> Calculates the escape velocity for an object from a sphericaly simmetrical, non-rotating
!> massive body of mass m and a given radius.
!>
!> Arguments:
!> - p_m_mass_kg: mass m, in kg.
!> - p_radius_km: radius of the object whose mass is M.
!>
!> Output:
!> - Escape velocity, expressed in km/s.
!>
!> NEEDS CHECKING TO ACCOUNT FOR RELATIVISTIC EFFECTS.
!>
pure real( kind = fmath2_p1 ) function RspFEscapeVelocity( p_m_mass_kg, p_radius_km )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_m_mass_kg, p_radius_km
RspFEscapeVelocity = ( 2.0 * ( RspFStandardGravitationalParameter( p_m_mass_kg ) / p_radius_km ) )**(0.5)
return
end function
!> Returns the standard gravitational parameter of a celestial body, measured in km**3 * s**-2.
!>
!> Arguments:
!> - p_mass_kg: mass of the object in question, expressed in kg.
!>
!> Output:
!> - Standard gratitational parameter of a celestial body, measured in km**3 * s**-2.
!>
pure real( kind = fmath2_p1 ) function RspFStandardGravitationalParameter( p_mass_kg )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_mass_kg
RspFStandardGravitationalParameter = ( RspFConst("G") * p_mass_kg ) / 10**9
return
end function
!> Calculates the radius of the theoretical event horizon of a non-rotating object.
!>
!> Arguments:
!> - p_mass_kg: Mass of the spherial, non-rotating object, in kg.
!>
!> Output:
!> - Radius of the event horizon, defined as the radius from which the escape velocity
!> equals the speed of light, expressed in km.
!>
pure real( kind = fmath2_p1 ) function RspFFindEventHorizon( p_mass_kg )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_mass_kg
! Escape velocity Ve should equal speed light in the case of an event horizon.
RspFFindEventHorizon = 2.0 * ( RspFStandardGravitationalParameter( p_mass_kg ) / ( RspFConst("c") )**2 )
return
end function
!> Returns the gravitational binding energy ratio of a non uniform spherical system.
!>
!> Arguments:
!> - p_mass_kg: mass of a body, in kg.
!> - p_radus_km: radius of the pody of mass p_mass_kg, in km.
!>
!> Output:
!> - Gravitational binding energy of a body of given mass and radius, expressed in Joules.
!>
!> Sources:
!> - [1] https://en.wikipedia.org/wiki/Gravitational_binding_energy
!>
!> NEEDS TESTING.
!>
pure real( kind = fmath2_p1 ) function RspFGravitationalBindingEnergyNus( p_mass_kg,p_radius_km )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_mass_kg,p_radius_km
RspFGravitationalBindingEnergyNus = ( RspFConst("c")**2 * p_mass_kg ) / ( p_radius_km - ( 738313.0 * p_mass_kg ) )
return
end function
!> Returns the gravitational binding energy of a uniform spherical system of uniform density.
!>
!> Arguments:
!> - p_mass_kg: mass of a body, in kg.
!> - p_radus_km: radius of the pody of mass p_mass_kg, in km.
!>
!> Output:
!> - U: Gravitational binding energy of a body of given mass and radius, expressed in
!> Joules. Convention is U positive.
!>
!> Sources:
!> - [1] https://en.wikipedia.org/wiki/Gravitational_binding_energy
!>
!> NEEDS TESTING.
!>
pure real( kind = fmath2_p1 ) function RspFGravitationalBindingEnergyUs( p_mass_kg, p_radius_km )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_mass_kg, p_radius_km
RspFGravitationalBindingEnergyUs = ( 3.0 * RspFConst("G") * ( p_mass_kg )**2 ) / (5.0 * p_radius_km * 1000.0)
return
end function
!> Given two masses orbiting slowly, compared to the speed of light at a certain distance,
!> this function calculates the energy that such a system gives away.
!>
!> Arguments:
!> - p_mass1_kg: mass of the first body, in kg.
!> - p_mass2_kg: mass of the second body, in kg.
!> - p_r_km: distance separating the two bodies.
!>
!> Output:
!> - Energy that the described system gives away.
!>
!> Sources:
!> - https://en.wikipedia.org/wiki/Gravitational_wave
!>
!> NEEDS TESTING.
!>
pure real( kind = fmath2_p1 ) function RspFGravitationalWave( p_mass1_kg, p_mass2_kg, p_r_km )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_mass1_kg, p_mass2_kg, p_r_km
RspFGravitationalWave = ( -1.0 ) * ( 32.0 / 5.0 ) * ( ( RspFConst("G")**4 ) / &
( RspFConst("c")**5 ) ) * ( ( ( ( p_mass1_kg * p_mass2_kg )**2) * ( p_mass1_kg + &
p_mass2_kg ) ) / ( p_r_km**5 ) )
return
end function
!> Finds out if a body of a given mass and radius is a black hole based on the calculation
!> of its escape velocity. If VES >= c, given the parameters passed, the object is a black hole.
!>
!> Arguments:
!> - p_M_mass_kg: mass m, in kg.
!> - p_radius_km: radius of the object whose mass is m.
!>
!> Output:
!> - 0 if the body in question is not a BH, 1 if it is.
!>
pure real( kind = fmath2_p1 ) function RspFIsBlackHole( p_m_mass_kg, p_radius_km )
implicit none
real( kind = fmath2_p1 ), intent(in) :: p_m_mass_kg, p_radius_km
if ( ( RspFEscapeVelocity(p_M_mass_kg, p_radius_km) ) >= ( RspFConst("c") ) ) then