forked from EmelineBolmont/mercury-90
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_module.f90
More file actions
3132 lines (2815 loc) · 149 KB
/
user_module.f90
File metadata and controls
3132 lines (2815 loc) · 149 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
!******************************************************************************
! MODULE: user_module
!******************************************************************************
!
! DESCRIPTION:
!> @brief Module that contain user defined function. This module can call other module and subroutine.
!! The only public routine is mfo_user, that return an acceleration that
!! mimic a random force that depend on what the user want to model.
!
!******************************************************************************
module user_module
use types_numeriques
use mercury_globals
implicit none
private
public :: mfo_user
contains
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author
!> John E. Chambers
!
!> @date 2 March 2001
!
! DESCRIPTION:
!> @brief Applies an arbitrary force, defined by the user.
!!\n\n
!! If using with the symplectic algorithm MAL_MVS, the force should be
!! small compared with the force from the central object.
!! If using with the conservative Bulirsch-Stoer algorithm MAL_BS2, the
!! force should not be a function of the velocities.
!! \n\n
!! Code Units are in AU, days and solar mass * K2 (mass are in solar mass, but multiplied by K2 earlier in the code).
!
!> @note All coordinates and velocities must be with respect to central body
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine mfo_user (time,jcen,nbod,nbig,m,x,v,a)
! m = mass (in solar masses * K2)
! x = coordinates (x,y,z) with respect to the central body [AU]
! v = velocities (vx,vy,vz) with respect to the central body [AU/day]
! nbod = current number of bodies (INCLUDING the central object)
! nbig = " " " big bodies (ones that perturb everything else)
! time = current epoch [days]
use physical_constant
use mercury_constant
use tides_constant_GR
use orbital_elements, only : mco_x2el
use spline
implicit none
! Input
integer, intent(in) :: nbod !< [in] current number of bodies (1: star; 2-nbig: big bodies; nbig+1-nbod: small bodies)
integer, intent(in) :: nbig !< [in] current number of big bodies (ones that perturb everything else)
real(double_precision), intent(in) :: time !< [in] current epoch (days)
real(double_precision), intent(in) :: jcen(3) !< [in] J2,J4,J6 for central body (units of RCEN^i for Ji)
real(double_precision), intent(in) :: m(nbod) !< [in] mass (in solar masses * K2)
real(double_precision), intent(in) :: x(3,nbod)
real(double_precision), intent(in) :: v(3,nbod)
! Output
real(double_precision),intent(out) :: a(3,nbod)
!---------------------------------------------------------------------------
!------Local-------
! Local
integer :: j,kk, error, iPs0, nptmss
integer :: flagrg2=0
integer :: flagtime=0
integer :: ispin=0
integer :: iwrite=0
integer :: charge_data = 0
real(double_precision) :: flagbug=0.d0
real(double_precision) :: timestep
! In case of BS integrator, we need time on previous timestep to know the
! current timestep
real(double_precision) :: time_bf
! Temporary orbital elements needed to calculate pseudo-synchronization for planets:
real(double_precision) :: gm,qq,ee,ii,pp,nn,ll
real(double_precision), dimension(ntid+1) :: qa,ea,ia,pa,na,la
! Initial rotation and rotation of the star:
real(double_precision) :: Pst0,Pst
! Love number for the star:
real(double_precision) :: k2s,k2fs
! Dissipation of the star:
real(double_precision) :: sigmast
! Total forces:
real(double_precision) :: F_tid_tot_x,F_tid_tot_y,F_tid_tot_z
real(double_precision) :: F_rot_tot_x,F_rot_tot_y,F_rot_tot_z
real(double_precision) :: F_GR_tot_x,F_GR_tot_y,F_GR_tot_z
!real(double_precision) :: acc_rot_x,acc_rot_y,acc_rot_z
!real(double_precision) :: acc_GR_x,acc_GR_y,acc_GR_z
! Sum of the forces
real(double_precision) :: sum_F_tid_x,sum_F_tid_y,sum_F_tid_z
real(double_precision) :: sum_F_rot_x,sum_F_rot_y,sum_F_rot_z
real(double_precision) :: sum_F_GR_x,sum_F_GR_y,sum_F_GR_z
! Torques for planets and star:
real(double_precision) :: N_tid_px,N_tid_py,N_tid_pz,N_tid_sx,N_tid_sy,N_tid_sz
real(double_precision) :: N_rot_px,N_rot_py,N_rot_pz,N_rot_sx,N_rot_sy,N_rot_sz
real(double_precision), dimension(3,nbig+1) :: Ns
! Runge Kutta terms (6 order):
real(double_precision) :: k_rk_1x,k_rk_2x,k_rk_3x,k_rk_4x,k_rk_5x,k_rk_6x
real(double_precision) :: k_rk_1y,k_rk_2y,k_rk_3y,k_rk_4y,k_rk_5y,k_rk_6y
real(double_precision) :: k_rk_1z,k_rk_2z,k_rk_3z,k_rk_4z,k_rk_5z,k_rk_6z
! Runge Kutta terms (6 order) for position and velocity of the first half of mercury timestep:
real(double_precision), dimension(3,nbig+1) :: xh_1_rk2,vh_1_rk2
real(double_precision), dimension(3,nbig+1) :: xh_1_rk3,vh_1_rk3
real(double_precision), dimension(3,nbig+1) :: xh_1_rk4,vh_1_rk4
real(double_precision), dimension(3,nbig+1) :: xh_1_rk5,vh_1_rk5
real(double_precision), dimension(3,nbig+1) :: xh_1_rk6,vh_1_rk6
! Runge Kutta terms (6 order) for position and velocity of the second half of mercury timestep:
real(double_precision), dimension(3,nbig+1) :: xh_2_rk2,vh_2_rk2
real(double_precision), dimension(3,nbig+1) :: xh_2_rk3,vh_2_rk3
real(double_precision), dimension(3,nbig+1) :: xh_2_rk4,vh_2_rk4
real(double_precision), dimension(3,nbig+1) :: xh_2_rk5,vh_2_rk5
real(double_precision), dimension(3,nbig+1) :: xh_2_rk6,vh_2_rk6
! Values of spin, radius and moments of inertia (rg) used for Runge Kutta
real(double_precision) :: spin0,spinp0,spinb0
real(double_precision) :: Rst,Rst_5,Rst_10,Rstb
real(double_precision) :: Rsth,Rsth5,Rsth10,Rstbh
real(double_precision) :: Rst0,Rst0_5,Rst0_10,Rstb0
real(double_precision) :: rg2s,rg2sh,rg2s0
! Position/velocity "before" (from previous steps) used for Runge Kutta::
real(double_precision), dimension(3,10) :: xh_bf,vh_bf,xh_bf2,vh_bf2
! Temporary value for runge kutta:
real(double_precision) :: xintermediate
! Temporary (tmp_dEdt is the derivative of the energy loss due to tides)
real(double_precision) :: tmp,tmp1,tmp_dEdt
! Time related and temporary things:
real(double_precision) :: dt,hdt
real(double_precision), dimension(3) :: bobo
! Integration of the spin (total torque tides):
real(double_precision), dimension(3) :: totftides
real(double_precision), dimension(3) :: sum_RK
! Temporary accelerations for each effect:
real(double_precision), dimension(3,nbig+1) :: a1,a2,a3
! Heliocentric coordinates:
real(double_precision), dimension(3,nbig+1) :: xh,vh
! Orbital angular momentum vector and norm for each planet:
real(double_precision), dimension(3,nbig+1) :: horb
real(double_precision), dimension(nbig+1) :: horbn
! Spins:
real(double_precision), dimension(3,10) :: spin,spin_bf
! Parameters for the planets: physical radius
real(double_precision), dimension(10) :: Rp,Rp5,Rp10
! Parameters for the planets: dissipation of the planet, general relativity stuff in tintin, love number, time lag, moments of inertia
real(double_precision), dimension(10) :: sigmap,tintin,k2p,k2fp,k2pdeltap,rg2p
! Data tables for evolving host body:
! - Data for Brown dwarf
real(double_precision), dimension(:), allocatable :: timeBD,radiusBD,lumiBD,HZinGJ,HZoutGJ,HZinb,HZoutb
real(double_precision), dimension(37) :: rg2st,trg2,rg1,rg2,rg3,rg4,rg5,rg6,rg7,rg8,rg9,rg10,rg11,rg12
! * Initial rotation period for brown dwarfs (BD)
real(double_precision), parameter, dimension(12) :: Ps0 = (/8.d0,13.d0,19.d0,24.d0,30.d0,36.d0,41.d0, &
47.d0,53.d0,58.d0,64.d0,70.d0/)
! * Love number for BD
real(double_precision), parameter, dimension(12) :: k2st = (/0.379d0,0.378d0,0.376d0,0.369d0, &
0.355d0,0.342d0,0.333d0,0.325d0,0.311d0,0.308d0,0.307d0,0.307d0/)
! - Data for Star
real(double_precision), dimension(2003) :: timestar,radiusstar,d2radiusstar
! - Data for M dwarf
real(double_precision), dimension(1065) :: timedM,radiusdM
! - Data for Jupiter
real(double_precision), dimension(4755) :: timeJup,radiusJup,k2Jup,rg2Jup,spinJup
character(len=80) :: planet_spin_filename
character(len=80) :: planet_orbt_filename
character(len=80) :: planet_dEdt_filename
! Save data of tables for evolving host body
! - Data for Brown Dwarf
save timeBD,radiusBD
save trg2,rg1,rg2,rg3,rg4,rg5,rg6,rg7,rg8,rg9,rg10,rg11,rg12
! - Date for Star
save timestar,radiusstar,d2radiusstar
! - Data for M dwarf
save timedM,radiusdM
! - Data for Jupiter
save timeJup,radiusJup,k2Jup,rg2Jup,spinJup
! Save data of radius of planet and star
save Rst0,Rst0_5,Rst0_10,rg2s0
!save Rst0,Rst0_5,Rst0_10
save Rp,Rp5,Rp10
! Save data for integration
save xh_bf,vh_bf,xh_bf2,vh_bf2
save timestep,nptmss
save spin_bf,dt,hdt
save tintin
! For BS integration
save time_bf
! for the dissipation calculation
save sigmast,k2s,k2fs
save k2p,k2fp,rg2p
! Flags
save flagrg2,flagtime,ispin,flagbug,charge_data
!------------------------------------------------------------------------------
! superzoyotte
! Error message
if (ispin.eq.0) then
if ((brown_dwarf.eq.1).and.((M_dwarf.eq.1).or.(Sun_like_star.eq.1).or.(Jupiter_host.eq.1).or.(Rscst.eq.1))) then
write(*,*) "You're trying to have a host body of two types at the same time, this is not going to work"
stop
endif
if ((M_dwarf.eq.1).and.((Sun_like_star.eq.1).or.(Jupiter_host.eq.1).or.(Rscst.eq.1).or.(brown_dwarf.eq.1))) then
write(*,*) "You're trying to have a host body of two types at the same time, this is not going to work"
stop
endif
if ((Sun_like_star.eq.1).and.((Jupiter_host.eq.1).or.(Rscst.eq.1).or.(brown_dwarf.eq.1).or.(M_dwarf.eq.1))) then
write(*,*) "You're trying to have a host body of two types at the same time, this is not going to work"
stop
endif
if ((Jupiter_host.eq.1).and.((Rscst.eq.1).or.(brown_dwarf.eq.1).or.(M_dwarf.eq.1).or.(Sun_like_star.eq.1))) then
write(*,*) "You're trying to have a host body of two types at the same time, this is not going to work"
stop
endif
if ((Rscst.eq.1).and.((brown_dwarf.eq.1).or.(M_dwarf.eq.1).or.(Sun_like_star.eq.1).or.(Jupiter_host.eq.1))) then
write(*,*) "You're trying to have a host body of two types at the same time, this is not going to work"
stop
endif
endif
! Acceleration initialization
do j = 1, nbod
a(1,j) = 0.d0
a(2,j) = 0.d0
a(3,j) = 0.d0
end do
do j=2,ntid+1
a1(1,j) = 0.d0
a1(2,j) = 0.d0
a1(3,j) = 0.d0
a2(1,j) = 0.d0
a2(2,j) = 0.d0
a2(3,j) = 0.d0
a3(1,j) = 0.d0
a3(2,j) = 0.d0
a3(3,j) = 0.d0
if (ispin.eq.0) then
qq = 0.d0
ee = 0.d0
pp = 0.d0
ii = 0.d0
nn = 0.d0
ll = 0.d0
qa(j) = 0.d0
ea(j) = 0.d0
pa(j) = 0.d0
ia(j) = 0.d0
na(j) = 0.d0
la(j) = 0.d0
endif
end do
if (iwrite.eq.0) then
call write_simus_properties()
iwrite = 1
endif
! Timestep calculation
if (flagtime.eq.0) then
bobo = get_initial_timestep()
dt = bobo(2)
hdt = 0.5d0*dt
flagtime = flagtime+1
if (crash.eq.0) timestep = 0.0d0
if (crash.eq.1) timestep = time + output * 365.25d0
write(*,*) 'integrator',algor
endif
if ((flagtime.ne.0).and.(algor.eq.2)) then
dt = time - time_bf
hdt = 0.5d0*dt
endif
! Following calculations in heliocentric coordinates
call conversion_dh2h(nbod,nbig,m,x,v,xh,vh)
if (ispin.eq.0) then
do j=2,ntid+1
xh_bf(1,j) = xh(1,j)
xh_bf(2,j) = xh(2,j)
xh_bf(3,j) = xh(3,j)
vh_bf(1,j) = vh(1,j)
vh_bf(2,j) = vh(2,j)
vh_bf(3,j) = vh(3,j)
enddo
endif
! Definition of factor used for GR force calculation
if (GenRel.eq.1) tintin(j) = m(1)*m(j)/(m(1)+m(j))**2
if (flagbug.ge.1) then
! If you have tides of rot flat
if ((tides.eq.1).or.(rot_flat.eq.1)) then
! Calculation of orbital angular momentum
! horb (without mass) in AU^2/day
do j=2,ntid+1
horb(1,j) = (xh(2,j)*vh(3,j)-xh(3,j)*vh(2,j))
horb(2,j) = (xh(3,j)*vh(1,j)-xh(1,j)*vh(3,j))
horb(3,j) = (xh(1,j)*vh(2,j)-xh(2,j)*vh(1,j))
horbn(j) = sqrt(horb(1,j)*horb(1,j)+horb(2,j)*horb(2,j)+horb(3,j)*horb(3,j))
end do
!-----------------------------------------------------------------------
! Charge host body data
if (charge_data.eq.0) then
if (brown_dwarf.eq.1) then
! BD's radius of gyration
open(1,file='rg2BD.dat')
do nptmss=1,37
read(1,*,iostat=error)trg2(nptmss),rg1(nptmss),rg2(nptmss), &
rg3(nptmss),rg4(nptmss),rg5(nptmss),rg6(nptmss),rg7(nptmss), &
rg8(nptmss),rg9(nptmss),rg10(nptmss),rg11(nptmss),rg12(nptmss)
end do
! If BD's mass is equal to one of these values, charge radius...
if ((m(1).le.0.0101*K2).and.(m(1).ge.0.0099*K2)) then
do j = 1,37
rg2st(j) = rg1(j)
enddo
open(1,file='mass_10.0000.dat')
nptmss = 715
allocate( timeBD(nptmss) )
allocate( radiusBD(nptmss))
allocate( lumiBD(nptmss) )
allocate( HZinGJ(nptmss) )
allocate( HZoutGJ(nptmss))
allocate( HZinb(nptmss) )
allocate( HZoutb(nptmss) )
do nptmss = 1,715
read(1,*,iostat=error)timeBD(nptmss),radiusBD(nptmss),lumiBD(nptmss), &
HZinGJ(nptmss),HZoutGJ(nptmss),HZinb(nptmss),HZoutb(nptmss)
end do
nptmss = nptmss - 1
else if ((m(1).le.0.0121*K2).and.(m(1).ge.0.0119*K2)) then
do j = 1,37
rg2st(j) = rg2(j)
enddo
open(1,file='mass_12.0000.dat')
nptmss = 720
allocate( timeBD(nptmss) )
allocate( radiusBD(nptmss))
allocate( lumiBD(nptmss) )
allocate( HZinGJ(nptmss) )
allocate( HZoutGJ(nptmss))
allocate( HZinb(nptmss) )
allocate( HZoutb(nptmss) )
do nptmss=1,720
read(1,*,iostat=error)timeBD(nptmss),radiusBD(nptmss),lumiBD(nptmss), &
HZinGJ(nptmss),HZoutGJ(nptmss),HZinb(nptmss),HZoutb(nptmss)
end do
nptmss = nptmss - 1
else if ((m(1).le.0.0151*K2).and.(m(1).ge.0.0149*K2)) then
do j = 1,37
rg2st(j) = rg3(j)
enddo
open(1,file='mass_15.0000.dat')
nptmss = 856
allocate( timeBD(nptmss) )
allocate( radiusBD(nptmss))
allocate( lumiBD(nptmss) )
allocate( HZinGJ(nptmss) )
allocate( HZoutGJ(nptmss))
allocate( HZinb(nptmss) )
allocate( HZoutb(nptmss) )
do nptmss=1,856
read(1,*,iostat=error)timeBD(nptmss),radiusBD(nptmss),lumiBD(nptmss), &
HZinGJ(nptmss),HZoutGJ(nptmss),HZinb(nptmss),HZoutb(nptmss)
end do
nptmss = nptmss - 1
else if ((m(1).le.0.0201*K2).and.(m(1).ge.0.0199*K2)) then
do j = 1,37
rg2st(j) = rg4(j)
enddo
open(1,file='mass_20.0000.dat')
nptmss = 864
allocate( timeBD(nptmss) )
allocate( radiusBD(nptmss))
allocate( lumiBD(nptmss) )
allocate( HZinGJ(nptmss) )
allocate( HZoutGJ(nptmss))
allocate( HZinb(nptmss) )
allocate( HZoutb(nptmss) )
do nptmss =1,864
read(1,*,iostat=error)timeBD(nptmss),radiusBD(nptmss),lumiBD(nptmss), &
HZinGJ(nptmss),HZoutGJ(nptmss),HZinb(nptmss),HZoutb(nptmss)
end do
nptmss = nptmss - 1
else if ((m(1).le.0.0301*K2).and.(m(1).ge.0.0299*K2)) then
do j = 1,37
rg2st(j) = rg5(j)
enddo
open(1,file='mass_30.0000.dat')
nptmss = 878
allocate( timeBD(nptmss) )
allocate( radiusBD(nptmss))
allocate( lumiBD(nptmss) )
allocate( HZinGJ(nptmss) )
allocate( HZoutGJ(nptmss))
allocate( HZinb(nptmss) )
allocate( HZoutb(nptmss) )
do nptmss=1,878
read(1,*,iostat=error)timeBD(nptmss),radiusBD(nptmss),lumiBD(nptmss), &
HZinGJ(nptmss),HZoutGJ(nptmss),HZinb(nptmss),HZoutb(nptmss)
end do
nptmss = nptmss - 1
else if ((m(1).le.0.0401*K2).and.(m(1).ge.0.0399*K2)) then
do j = 1,37
rg2st(j) = rg6(j)
enddo
open(1,file='mass_40.0000.dat')
nptmss = 886
allocate( timeBD(nptmss) )
allocate( radiusBD(nptmss))
allocate( lumiBD(nptmss) )
allocate( HZinGJ(nptmss) )
allocate( HZoutGJ(nptmss))
allocate( HZinb(nptmss) )
allocate( HZoutb(nptmss) )
do nptmss = 1,886
read(1,*,iostat=error)timeBD(nptmss),radiusBD(nptmss),lumiBD(nptmss), &
HZinGJ(nptmss),HZoutGJ(nptmss),HZinb(nptmss),HZoutb(nptmss)
end do
nptmss = nptmss - 1
else if ((m(1).le.0.0501*K2).and.(m(1).ge.0.0499*K2)) then
do j = 1,37
rg2st(j) = rg7(j)
enddo
open(1,file='mass_50.0000.dat')
nptmss = 891
allocate( timeBD(nptmss) )
allocate( radiusBD(nptmss))
allocate( lumiBD(nptmss) )
allocate( HZinGJ(nptmss) )
allocate( HZoutGJ(nptmss))
allocate( HZinb(nptmss) )
allocate( HZoutb(nptmss) )
do nptmss=1,891
read(1,*,iostat=error)timeBD(nptmss),radiusBD(nptmss),lumiBD(nptmss), &
HZinGJ(nptmss),HZoutGJ(nptmss),HZinb(nptmss),HZoutb(nptmss)
end do
nptmss = nptmss - 1
else if ((m(1).le.0.0601*K2).and.(m(1).ge.0.0599*K2)) then
do j = 1,37
rg2st(j) = rg8(j)
enddo
open(1,file='mass_60.0000.dat')
nptmss = 1663
allocate( timeBD(nptmss) )
allocate( radiusBD(nptmss))
allocate( lumiBD(nptmss) )
allocate( HZinGJ(nptmss) )
allocate( HZoutGJ(nptmss))
allocate( HZinb(nptmss) )
allocate( HZoutb(nptmss) )
do nptmss=1,1663
read(1,*,iostat=error)timeBD(nptmss),radiusBD(nptmss),lumiBD(nptmss), &
HZinGJ(nptmss),HZoutGJ(nptmss),HZinb(nptmss),HZoutb(nptmss)
end do
nptmss = nptmss - 1
else if ((m(1).le.0.0701*K2).and.(m(1).ge.0.0699*K2)) then
do j = 1,37
rg2st(j) = rg9(j)
enddo
open(1,file='mass_70.0000.dat')
nptmss = 3585
allocate( timeBD(nptmss) )
allocate( radiusBD(nptmss))
allocate( lumiBD(nptmss) )
allocate( HZinGJ(nptmss) )
allocate( HZoutGJ(nptmss))
allocate( HZinb(nptmss) )
allocate( HZoutb(nptmss) )
do nptmss =1,3585
read(1,*,iostat=error)timeBD(nptmss),radiusBD(nptmss),lumiBD(nptmss), &
HZinGJ(nptmss),HZoutGJ(nptmss),HZinb(nptmss),HZoutb(nptmss)
end do
nptmss = nptmss - 1
else if ((m(1).le.0.0721*K2).and.(m(1).ge.0.0719*K2)) then
do j = 1,37
rg2st(j) = rg10(j)
enddo
open(1,file='mass_72.0000.dat')
nptmss = 3721
allocate( timeBD(nptmss) )
allocate( radiusBD(nptmss))
allocate( lumiBD(nptmss) )
allocate( HZinGJ(nptmss) )
allocate( HZoutGJ(nptmss))
allocate( HZinb(nptmss) )
allocate( HZoutb(nptmss) )
do nptmss =1,3721
read(1,*,iostat=error)timeBD(nptmss),radiusBD(nptmss),lumiBD(nptmss), &
HZinGJ(nptmss),HZoutGJ(nptmss),HZinb(nptmss),HZoutb(nptmss)
end do
nptmss = nptmss - 1
else if ((m(1).le.0.0751*K2).and.(m(1).ge.0.0749*K2)) then
do j = 1,37
rg2st(j) = rg11(j)
enddo
open(1,file='mass_75.0000.dat')
nptmss = 3903
allocate( timeBD(nptmss) )
allocate( radiusBD(nptmss))
allocate( lumiBD(nptmss) )
allocate( HZinGJ(nptmss) )
allocate( HZoutGJ(nptmss))
allocate( HZinb(nptmss) )
allocate( HZoutb(nptmss) )
do nptmss =1,3903
read(1,*,iostat=error)timeBD(nptmss),radiusBD(nptmss),lumiBD(nptmss), &
HZinGJ(nptmss),HZoutGJ(nptmss),HZinb(nptmss),HZoutb(nptmss)
end do
nptmss = nptmss - 1
else if ((m(1).le.0.0801*K2).and.(m(1).ge.0.0799*K2)) then
do j = 1,37
rg2st(j) = rg12(j)
enddo
open(1,file='mass_80.0000.dat')
nptmss = 4161
allocate( timeBD(nptmss) )
allocate( radiusBD(nptmss))
allocate( lumiBD(nptmss) )
allocate( HZinGJ(nptmss) )
allocate( HZoutGJ(nptmss))
allocate( HZinb(nptmss) )
allocate( HZoutb(nptmss) )
do nptmss =1,4161
read(1,*,iostat=error)timeBD(nptmss),radiusBD(nptmss),lumiBD(nptmss), &
HZinGJ(nptmss),HZoutGJ(nptmss),HZinb(nptmss),HZoutb(nptmss)
end do
nptmss = nptmss - 1
endif
endif
! Charge file of radius of Mdwarf
if (M_dwarf.eq.1) then
open(1,file='01Msun.dat')
do nptmss = 1,1065
read(1,*,iostat=error)timedM(nptmss),radiusdM(nptmss)
end do
nptmss = nptmss - 1
endif
! Charge file of radius of Sun-like star
if (Sun_like_star.eq.1) then
open(1,file='SRad_Spli_M-1_0000.dat')
do nptmss = 1,2003
read(1,*,iostat=error)timestar(nptmss),radiusstar(nptmss),d2radiusstar(nptmss)
end do
nptmss = nptmss - 1
endif
! Charge file of radius of Jupiter
if (Jupiter_host.eq.1) then
open(1,file='Jupiter.dat')
do nptmss = 1,4755
read(1,*,iostat=error) timeJup(nptmss),radiusJup(nptmss) &
,k2Jup(nptmss),rg2Jup(nptmss),spinJup(nptmss)
end do
nptmss = nptmss - 1
endif
charge_data = 1
endif
!-------------------------------------------------------------------
!-------------------------------------------------------------------
!---------------- Initial condition on host body spin ------------
!-------------------- and then for planets -----------------------
!-------------------------------------------------------------------
!-------------------------------------------------------------------
if (flagbug.eq.1) then
!---------------------------------------------------------------
!------------------------- HOST BODY -------------------------
!---------------------------------------------------------------
!---------------------------------------------------------------
!----------------------- BROWN DWARF -------------------------
if (brown_dwarf.eq.1) then
! Here defining k2s and initial rotation period of BD
if ((m(1).le.0.0101*K2).and.(m(1).ge.0.0099*K2)) then
iPs0 = 1
k2s = k2st(iPs0)
Pst0 = Ps0(iPs0)
else if ((m(1).le.0.0121*K2).and.(m(1).ge.0.0119*K2)) then
iPs0 = 2
k2s = k2st(iPs0)
Pst0 = Ps0(iPs0)
else if ((m(1).le.0.0151*K2).and.(m(1).ge.0.0149*K2)) then
iPs0 = 3
k2s = k2st(iPs0)
Pst0 = Ps0(iPs0)
else if ((m(1).le.0.0201*K2).and.(m(1).ge.0.0199*K2)) then
iPs0 = 4
k2s = k2st(iPs0)
Pst0 = Ps0(iPs0)
else if ((m(1).le.0.0301*K2).and.(m(1).ge.0.0299*K2)) then
iPs0 = 5
k2s = k2st(iPs0)
Pst0 = Ps0(iPs0)
else if ((m(1).le.0.0401*K2).and.(m(1).ge.0.0399*K2)) then
iPs0 = 6
k2s = k2st(iPs0)
Pst0 = Ps0(iPs0)
else if ((m(1).le.0.0501*K2).and.(m(1).ge.0.0499*K2)) then
iPs0 = 7
k2s = k2st(iPs0)
Pst0 = Ps0(iPs0)
else if ((m(1).le.0.0601*K2).and.(m(1).ge.0.0599*K2)) then
iPs0 = 8
k2s = k2st(iPs0)
Pst0 = Ps0(iPs0)
else if ((m(1).le.0.0701*K2).and.(m(1).ge.0.0699*K2)) then
iPs0 = 9
k2s = k2st(iPs0)
Pst0 = Ps0(iPs0)
else if ((m(1).le.0.0721*K2).and.(m(1).ge.0.0719*K2)) then
iPs0 = 10
k2s = k2st(iPs0)
Pst0 = Ps0(iPs0)
else if ((m(1).le.0.0751*K2).and.(m(1).ge.0.0749*K2)) then
iPs0 = 11
k2s = k2st(iPs0)
Pst0 = Ps0(iPs0)
else if ((m(1).le.0.0801*K2).and.(m(1).ge.0.0799*K2)) then
iPs0 = 12
k2s = k2st(iPs0)
Pst0 = Ps0(iPs0)
endif
! Fluid Love number = potential Love number
k2fs = k2s
! Dissipation for the BD
sigmast = dissstar*sigma_BD
! Initialization of the things that change: radius and radius of
! gyration
if (crash.eq.0) then
! Determination of the radius at time = t_init
call spline_b_val(nptmss,timeBD*365.25d0-t_init,radiusBD,time,Rstb0)
! Determination of the radius of gyration at time = t_init
call spline_b_val(37,trg2*365.25d0-t_init,rg2st,time,rg2s0)
else
! Determination of the radius at time = t_crash
call spline_b_val(nptmss,timeBD*365.25d0-t_init,radiusBD,time-t_crash,Rstb0)
! Determination of the radius of gyration at time = t_crash
call spline_b_val(37,trg2*365.25d0-t_init,rg2st,time-t_crash,rg2s0)
endif
Rst0 = Rsun * Rstb0
Rst0_5 = Rst0*Rst0*Rst0*Rst0*Rst0
Rst0_10 = Rst0_5*Rst0_5
! I use here Rsth and rg2s because it is the one used in the
! expression of the force later on
Rsth = Rst0
Rsth5 = Rst0_5
Rsth10 = Rst0_10
rg2s = rg2s0
Rst = Rst0
Rst_5 = Rst0_5
Rst_10 = Rst0_10
rg2sh = rg2s0
endif
!---------------------------------------------------------------
!------------------------- M DWARF ---------------------------
if (M_dwarf.eq.1) then
! radius of gyration
rg2s = rg2_dM
! potential love number
k2s = k2st_dM
! fluid love number
k2fs = k2fst_what
! Dissipation for the dM
sigmast = dissstar*sigma_dM
! Value of initial rotation period for dM
Pst = Period_st
! Initialization of the things that change: radius and radius of
! gyration
if (crash.eq.0) then
! Determination of the radius at time = t_init
call spline_b_val(nptmss,timedM*365.25-t_init,radiusdM,time,Rstb0)
else
! Determination of the radius at time = t_crash
call spline_b_val(nptmss,timedM*365.25-t_init,radiusdM,time-t_crash,Rstb0)
endif
Rst0 = Rsun * Rstb0
Rst0_5 = Rst0*Rst0*Rst0*Rst0*Rst0
Rst0_10 = Rst0_5*Rst0_5
! I use here Rsth because it is the one used in the expression of
! the force later on
Rsth = Rst0
Rsth5 = Rst0_5
Rsth10 = Rst0_10
Rst = Rst0
Rst_5 = Rst0_5
Rst_10 = Rst0_10
rg2sh = rg2s0
endif
!---------------------------------------------------------------
!---------------------- SUN LIKE STAR ------------------------
if (Sun_like_star.eq.1) then
! radius of gyration
rg2s = rg2_Sun
! potential love number
k2s = k2st_Sun
! fluid love number
k2fs = k2fst_what
! Dissipation for the Sun-like star
sigmast = dissstar*sigma_Sun
! Value of initial rotation period for Sun-like star
Pst = Period_st
! Initialization of the things that change: radius and radius of
! gyration
if (crash.eq.0) then
! Determination of the radius at time = t_init
call spline_b_val(nptmss,timestar*365.25-t_init,radiusstar,time,Rstb0)
else
! Determination of the radius at time = t_crash
call spline_b_val(nptmss,timestar*365.25-t_init,radiusstar,time-t_crash,Rstb0)
endif
Rst0 = minau * Rstb0
Rst0_5 = Rst0*Rst0*Rst0*Rst0*Rst0
Rst0_10 = Rst0_5*Rst0_5
! I use here Rsth because it is the one used in the expression of
! the force later on
Rsth = Rst0
Rsth5 = Rst0_5
Rsth10 = Rst0_10
Rst = Rst0
Rst_5 = Rst0_5
Rst_10 = Rst0_10
rg2sh = rg2s0
endif
!---------------------------------------------------------------
!------------------------- JUPITER ---------------------------
if (Jupiter_host.eq.1) then
! Initialization of the things that change: radius and radius of
! gyration and love number
if (crash.eq.0) then
! Determination of the radius at time = t_init
call spline_b_val(nptmss,timeJup*365.25d0-t_init,radiusJup,time,Rstb0)
! Determination of the radius of gyration at time = t_init
call spline_b_val(nptmss,timeJup*365.25d0-t_init,rg2Jup,time,rg2s0)
! Determination of the love number at time = t_init
call spline_b_val(nptmss,timeJup*365.25d0-t_init,k2Jup,time,k2s)
else
call spline_b_val(nptmss,timeJup*365.25d0-t_init,radiusJup,time-t_crash,Rstb0)
call spline_b_val(nptmss,timeJup*365.25d0-t_init,rg2Jup,time-t_crash,rg2s0)
call spline_b_val(nptmss,timeJup*365.25d0-t_init,k2Jup,time-t_crash,k2s)
endif
Rst0 = minau * Rstb0
Rst0_5 = Rst0*Rst0*Rst0*Rst0*Rst0
Rst0_10 = Rst0_5*Rst0_5
! fluid love number = potential Love number
k2fs = k2s
! I use here Rsth and rg2s because it is the one used in the expression of
! the force later on
Rsth = Rst0
Rsth5 = Rst0_5
Rsth10 = Rst0_10
rg2s = rg2s0
Rst = Rst0
Rst_5 = Rst0_5
Rst_10 = Rst0_10
rg2sh = rg2s0
! Dissipation for Jupiter
sigmast = dissstar*2.d0*K2*k2delta_jup/(3.d0*Rst0_5)
endif
!---------------------------------------------------------------
!----------------------- NON EVOLVING -------------------------
if (Rscst.eq.1) then
! radius of gyration
rg2s = rg2_what
! potential love number
k2s = k2st_what
! fluid love number
k2fs = k2fst_what
! Value of initial rotation period
Pst = Period_st
! Value of the radius
Rsth = radius_star*rsun
Rsth5 = Rsth*Rsth*Rsth*Rsth*Rsth
Rsth10 = Rsth5*Rsth5
Rst = Rsth
Rst_5 = Rsth5
Rst_10 = Rsth10
! Dissipation
if (sigma_what.gt.0) sigmast = dissstar*sigma_what
if (k2sdeltats.gt.0) sigmast = dissstar*2.d0*K2*k2sdeltats/(3.d0*Rsth5)
endif
!---------------------------------------------------------------
!------------- Initialization of stellar spin (day-1) --------
if (crash.eq.0) then
if (brown_dwarf.eq.1) spin0 = 24.d0*TWOPI/Pst0
if ((M_dwarf.eq.1).or.(Sun_like_star.eq.1).or.(Rscst.eq.1)) spin0 = TWOPI/Pst
if (Jupiter_host.eq.1) then
! spinJup in s-1, conversion in day-1
call spline_b_val(nptmss,timeJup*365.25-t_init,spinJup,time,spinb0)
spin0 = spinb0*86400.d0
endif
spin(1,1) = 0.d0
spin(2,1) = 0.d0
spin(3,1) = spin0
else
spin(1,1) = rot_crash(1)
spin(2,1) = rot_crash(2)
spin(3,1) = rot_crash(3)
endif
!---------------------------------------------------------------
!-------------------------- PLANETS --------------------------
!---------------------------------------------------------------
do j=2,ntid+1
!-----------------------------------------------------------
!------------------ Planetary radius in AU ---------------
! If planet_type eq 0, rocky planet with prescription mass-radius
if (planet_type(j-1).eq.0) Rp(j) = rearth*((0.0592d0*0.7d0+0.0975d0) &
*(dlog10(m(j))+dlog10(m2earth)-dlog10(K2))**2+(0.2337d0*0.7d0+0.4938d0) &
*(dlog10(m(j))+dlog10(m2earth)-dlog10(K2))+0.3102d0*0.7d0+0.7932d0)
! If planet_type ne 0, value given by radius_p of tides_constants
if (planet_type(j-1).ne.0) Rp(j) = radius_p(j-1)*rearth
Rp5(j) = Rp(j)*Rp(j)*Rp(j)*Rp(j)*Rp(j)
Rp10(j) = Rp5(j)*Rp5(j)
!-----------------------------------------------------------
!------------------ Planetary radius of gyration ---------
!--------------- love number and fluid love number -------
!------------------ planetary dissipation ----------------
! planet_type = 0 or 1: terrestrial planet
if ((planet_type(j-1).eq.0).or.(planet_type(j-1).eq.1)) then
rg2p(j-1) = rg2p_terr
k2p(j-1) = k2p_terr
k2fp(j-1) = k2fp_terr
if (tides.eq.1) then
k2pdeltap(j-1) = k2pdeltap_terr
sigmap(j) = dissplan(j-1)*2.d0*K2*k2pdeltap(j-1)/(3.d0*Rp5(j))
endif
endif
! planet_type = 2: gas giant (Jupiter)
if (planet_type(j-1).eq.2) then
rg2p(j-1) = rg2p_gg
k2p(j-1) = k2p_gg
k2fp(j-1) = k2p_gg
if (tides.eq.1) then
k2pdeltap(j-1) = k2pdeltap_gg
sigmap(j) = dissplan(j-1)*sigma_gg
endif
endif
! planet_type = 3: you give the values you want in tides_constant_GR
if (planet_type(j-1).eq.3) then
rg2p(j-1) = rg2p_what(j-1)
k2p(j-1) = k2tp_what(j-1)
k2fp(j-1) = k2fp_what(j-1)
if (tides.eq.1) then
k2pdeltap(j-1) = k2pdeltap_what(j-1)
sigmap(j) = dissplan(j-1)*2.d0*K2*k2pdeltap(j-1)/(3.d0*Rp5(j))
endif
endif
enddo
!--------------------------------------------------------------------
!------------ Initialization of spin of planets (day-1) -----------
if (crash.eq.0) then
do j=2,ntid+1
! if pseudo_rot eq 0, then rotation period given in
! tides_constants
if (pseudo_rot(j-1).eq.0) spinp0 = 24.d0*TWOPI/Pp0(j-1)
! Initially I need the orbital elements to compute
! pseudo-synchronization and initial direction of spins
! gm is in AU^3.day^-2
gm = m(1) + m(j)
call mco_x2el(gm,xh(1,j),xh(2,j),xh(3,j),vh(1,j),vh(2,j),vh(3,j),qq,ee,ii,pp,nn,ll)
qa(j) = qq
ea(j) = ee
pa(j) = pp
ia(j) = ii
na(j) = nn
la(j) = ll
! if pseudo_rot eq 1, then pseudo-synchronization
if (pseudo_rot(j-1).ne.0) then
spinp0 = pseudo_rot(j-1)*(1.d0+15.d0/2.d0*ea(j)**2+45.d0/8.d0*ea(j)**4+5.d0/16.d0*ea(j)**6) &
*1.d0/(1.d0+3.d0*ea(j)**2+3.d0/8.d0*ea(j)**4)*1./(1-ea(j)**2)**1.5d0*sqrt(m(1)+m(j)) &
*(qa(j)/(1.d0-ea(j)))**(-1.5d0)
endif
! If the planet has no inclination
if (ia(j).eq.0.0) then
spin(1,j) = 0.0d0
spin(2,j) = -spinp0*sin(oblp(j-1))
spin(3,j) = spinp0*cos(oblp(j-1))
endif
! If the planet has an inclination
if (ia(j).ne.0.0) then
spin(1,j) = 0.0d0
spin(2,j) = -spinp0*sin(oblp(j-1)+ia(j))
spin(3,j) = spinp0*cos(oblp(j-1)+ia(j))
endif
enddo
else
spin(1,2) = rot_crashp1(1) !day-1
spin(2,2) = rot_crashp1(2) !day-1
spin(3,2) = rot_crashp1(3) !day-1
if (ntid.ge.2) then
spin(1,3) = rot_crashp2(1) !day-1
spin(2,3) = rot_crashp2(2) !day-1
spin(3,3) = rot_crashp2(3) !day-1
endif
if (ntid.ge.3) then
spin(1,4) = rot_crashp3(1) !day-1
spin(2,4) = rot_crashp3(2) !day-1
spin(3,4) = rot_crashp3(3) !day-1
endif
if (ntid.ge.4) then
spin(1,5) = rot_crashp4(1) !day-1
spin(2,5) = rot_crashp4(2) !day-1