-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.F90
1804 lines (1618 loc) · 74.2 KB
/
main.F90
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
program main
use forces
use integrators
implicit none
call init_default_parameters() ! Inicializamos parámetros
existe_configfile = .True. ! Existe archivo de configuración
arguments_number = command_argument_count()
do i = 1, arguments_number
call get_command_argument(i, aux_character30)
if (trim(aux_character30) .eq. "--noconfig") then
existe_configfile = .False.
exit
end if
end do
call read_config_file("config.ini", existe_configfile) ! Leemos archivo de configuración
if (.not. existe_configfile) then ! Usaremos parámetros por defecto
! Asteroide central
!! Primary
mass_primary = 6.3d18 ! Masa del cuerpo 0 [kg] ! -x => mAst = x
radius_primary = 129.d0 ! Radio del cuerpo 0 [km]
!! ROTACIÓN
asteroid_rotational_period = 7.004d0/24.d0 ! Periodo de rotación [day]
!lambda_kep = 0.471d0 ! Cociente omega/wk
!! Boulders
Nboulders = 1 ! Número de boulders
if (Nboulders > 0) then
!! Alocamos (No tocar)
call allocate_asteriod_arrays(Nboulders)
!!!!! COCIENTE DE MASAS
mu_from_primary(1) = 1.d-1 ! Cociente de masas entre boulder 1 y primary
! mu_from_primary(2) = 1.d-6 ! Cociente de masas entre boulder 2 y primary
! mu_from_primary(3) = 1.d-4 ! Cociente de masas entre boulder 3 y primary
! mu_from_primary(4) = 1.d-7 ! Cociente de masas entre boulder 4 y primary
!!! ÁNGULOS DE FASE RESPECTO AL ORIGEN [deg]
theta_from_primary(1) = cero ! Ángulo de fase del boulder 1[deg]
! theta_from_primary(2) = 90 ! Ángulo de fase del boulder 2[deg]
! theta_from_primary(3) = 180 ! Ángulo de fase del boulder 3[deg]
! theta_from_primary(4) = 270 ! Ángulo de fase del boulder 4[deg]
!!! RADIOS
radius_ast_arr(1) = 2.5d0 ! Radio del boulder 1 [km]
! radius_ast_arr(2) = 1.5d0 ! Radio del boulder 2 [km]
! radius_ast_arr(3) = 3.5d0 ! Radio del boulder 3 [km]
! radius_ast_arr(4) = 2.5d0 ! Radio del boulder 3 [km]
end if
!!!! Merges (colliding particles into asteroid)
use_merge = .True. ! Merge particles into asteroid
!!!! Torque
use_torque = .False. ! Cant be used with explicit method, or exponential omega damping
!!!! Stokes
use_stokes = .False.
stokes_a_damping_time = infinity ! [day]
stokes_e_damping_time = stokes_a_damping_time / 1.d2 ! [day]
stokes_charac_time = cero ! [day] Tiempo que actua stokes
!!!! Naive-Stokes (drag)
use_naive_stokes = .False.
drag_coefficient = cero ! Eta
drag_charac_time = cero ! [day] Tiempo que actua drag
!!!! Geo-Potential (J2)
use_J2 = .False.
J2_coefficient = cero
!!! Parámetros corrida
!!!! Tiempos
initial_time = cero ! Initial time [day]
final_time = 2.d3 ! Final time [day]
min_timestep = cero ! Min timestep [day] ! Almost unused
case_output_type = 0 ! 0: Linear ; 1: Logarithmic ; 2: Combination
output_number = 10000 ! Number of outputs (if dt_out=0)
output_timestep = cero ! Output timestep [day] (used if case_output_type != 1)
!!!! Error
learning_rate = 0.85d0 ! [For adaptive step integrators] Learning rate
error_digits = 12 ! [For adaptive step integrators] Digits for relative error
!!!! Colision y escape
min_distance = -1.5d0 ! Min distance before impact [km] ! 0 => R0 + max(Rboul)
max_distance = -1.d2 ! Max distance before escape [km] ! -x => R0 * x
!!!! Particle elements
use_single_particle = .False. ! Single particle? (THIS ONE BELOW)
single_part_mass = 6.3e14 ! Mass of the particle [kg]
single_part_elem_a = cero ! Element a of the particle [km]
single_part_elem_e = cero !0.1d0 ! ecc
single_part_elem_M = cero ! Mean anomaly (deg)
single_part_elem_w = cero ! Pericenter argument (deg)
single_part_MMR = 5.2d0 !1.001d0 !3.3d0 ! resonancia nominal correspondiente
!!! Output: "" or "no", if not used
datafile = ""
chaosfile = ""
mapfile = ""
multfile = ""
!!!!! Screeen
use_datascreen = .True. ! Print data in screen
use_screen = .True. ! Print info in screen
!!! Input: "" or "no", if not used
tomfile = ""
particlesfile = ""
!!! Parallel
use_parallel = .False.
requested_threads = 1 ! Number of threads to use !! -1 => all available
end if
call load_command_line_arguments()
call set_derived_parameters() ! Inicializamos parámetros derivados
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!! No tocar de aquí a abajo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!! OUTPUT !!!!!!!!!!
if ((trim(datafile) /= "") .and. (trim(datafile) /= "no")) then
use_datafile = .True.
else
use_datafile = .False.
end if
if ((trim(chaosfile) /= "") .and. (trim(chaosfile) /= "no")) then
use_chaosfile = .True.
use_chaos = .True.
else
use_chaosfile = .False.
end if
if ((trim(multfile) /= "") .and. (trim(multfile) /= "no")) then
use_multiple_outputs = .True.
else
use_multiple_outputs = .False.
end if
if ((trim(mapfile) /= "") .and. (trim(mapfile) /= "no")) then
use_potential_map = .True.
else
use_potential_map = .False.
end if
if ((trim(tomfile) /= "") .and. (trim(tomfile) /= "no")) then
use_tomfile = .True.
else
use_tomfile = .False.
end if
if ((trim(particlesfile) /= "") .and. (trim(particlesfile) /= "no")) then
use_particlesfile = .True.
else
use_particlesfile = .False.
end if
if (.not. any((/use_datascreen, use_datafile, use_chaosfile, use_potential_map, use_multiple_outputs/))) then ! No tiene sentido hacer nada
if (.not. use_screen) then
write (*,*) ACHAR(10)
write (*,*) "EXITING: No se guardará ni imprimirá ninguna salida."
stop 1
else
write (*,*) "WARNING: No se integrará. Solo se imprimirá en pantalla información."
end if
end if
if (.not. any((/use_single_particle, use_particlesfile/))) then ! No tiene sentido hacer nada
write (*,*) ACHAR(10)
write (*,*) "EXITING: No se integrará ninguna partícula."
stop 1
end if
! Mensaje
if (use_screen .and. .not. existe_configfile) then
write (*,*) "WARNING: No se pudo leer el archivo de configuración: config.ini"
write (*,*) " Se utilizan los parámetros dados en el código."
end if
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NBOULDERS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (.not. use_boulders) then
write (*,*) "WARNING: No se integrarán boulders."
write (*,*) " Se utilizará un asteroide sin boulders, y sin efectos por rotación."
end if
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Parallel !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (use_screen) then
write (*,*) ACHAR(5)
if (use_parallel) then
write (*,*) "---------- Parallel integration----------"
write (*,f12) " Available threads:", available_threads
write (*,f12) " Requested threads:", requested_threads
write (*,f12) " Used threads :", my_threads
else
write (*,*) "---------- Serial integration ----------"
end if
write (*,*) ACHAR(5)
end if
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!! COMIENZO DE CÁLCULOS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (use_screen) then
write (*,*) ACHAR(5)
write (*,f12) "Comenzando simulación: ", simulation_number
write (*,*) ACHAR(5)
write (*,*) "---------- Parámetros iniciales ----------"
write (*,*) ACHAR(5)
end if
!!!!!!!!!!!!!!!!!!!!!!!!!! Asteroide y Boulders !!!!!!!!!!!!!!!!!!!!!!!!!!
! Radios (unidades)
radius_primary = radius_primary * unit_dist ! Unidades según G
radius_ast_arr = radius_ast_arr * unit_dist ! Unidades según G
radius_ast_arr(0) = radius_primary ! Radio del cuerpo 0
! Masas
mass_primary = mass_primary * unit_mass ! Unidades según G
!! Check if mass_primary < 0. If so, |mass_primary| should be asteroid mass
if (mass_primary < cero) mass_primary = abs(mass_primary) / (uno + sum(mu_from_primary(1:Nboulders)))
mass_ast_arr(0) = mass_primary ! Masa del cuerpo 0
do i = 1, Nboulders
mass_ast_arr(i) = mu_from_primary(i) * mass_primary ! Masa del boulder i
end do
asteroid_mass = sum(mass_ast_arr) ! Masa del sistema
mu_ast_arr = mass_ast_arr / asteroid_mass ! Mues respecto a mcm
Gmass_ast_arr = G * mass_ast_arr
Gasteroid_mass = G * asteroid_mass
! Rotaciones
omega_kep = sqrt(Gasteroid_mass / radius_primary**3) / unit_time ! Movimiento medio (kepleriano) que tendrían los boulder
if (lambda_kep > tini) then
asteroid_omega = omega_kep * lambda_kep ! Velocidad angular del cuerpo 0 [rad/day]
asteroid_rotational_period = twopi / asteroid_omega ! Periodo de rotación del cuerpo 0 [day]
else
asteroid_omega = (twopi / asteroid_rotational_period) / unit_time ! Velocidad angular del cuerpo 0 [rad/day]
lambda_kep = asteroid_omega / omega_kep ! Cociente de velocidades
end if
asteroid_omega2 = asteroid_omega * asteroid_omega
asteroid_a_corot = (Gasteroid_mass / asteroid_omega2)**(1/3.)
!! Mensaje
if (use_screen) then
write (*,*) "Rotación:"
write (*,f13) " a_corot :", asteroid_a_corot / unit_dist, "[km]"
write (*,f13) " omega :", asteroid_omega * unit_time, "[rad/day]"
write (*,f13) " omega_kep :", omega_kep * unit_time, "[rad/day]"
write (*,f13) " lambda_kep:", lambda_kep
write (*,f13) " Period :", asteroid_rotational_period * 24 * unit_time, "[hs]"
write (*,*) ACHAR(5)
write (*,f13) "Masa cuerpo central :", mass_primary / unit_mass, "[kg]"
write (*,f13) "Radio de cuerpo central:", radius_primary / unit_dist, "[km]"
write (*,*) ACHAR(5)
if (.not. use_boulders) then
write(*,*) "La rotación se considera solo para definir parámetros iniciales."
write (*,*) ACHAR(5)
end if
end if
! Coordenadas (Solo tienen sentido con boulders)
if (use_boulders) then
theta_from_primary = theta_from_primary * radian ! Ángulos de fase de los boulders [rad]
!! Astrocentricas
do i = 1, Nboulders
pos_from_primary(i,1) = radius_primary * cos(theta_from_primary(i)) ! Posición x del boulder i
pos_from_primary(i,2) = radius_primary * sin(theta_from_primary(i)) ! Posición x del boulder i
vel_from_primary(i,1) = - asteroid_omega * pos_from_primary(i,2) ! Velocidad x del boulder i
vel_from_primary(i,2) = asteroid_omega * pos_from_primary(i,1) ! Velocidad x del boulder i
acc_from_primary(i,1) = - asteroid_omega2 * pos_from_primary(i,1) ! Aceleración x del boulder i
acc_from_primary(i,2) = - asteroid_omega2 * pos_from_primary(i,2) ! Aceleración x del boulder i
end do
!!! Mensaje
if (use_screen) then
write (*,*) "Coordenadas:"
write (*,*) " m0-centricas: [x, y, vx, vy, ax, ay, mu, theta]"
do i = 1, Nboulders
write (*,f233) i, &
& pos_from_primary(i,:) / unit_dist, &
& pos_from_primary(i,:) / unit_vel, &
& acc_from_primary(i,:) / unit_acc, &
& mu_from_primary(i), &
& theta_from_primary(i) / radian
end do
write (*,*) ACHAR(5)
end if
end if
!! Centro de masas, desde primary
pos_ast_from_primary = cero
vel_ast_from_primary = cero
acc_ast_from_primary = cero
theta_ast_from_primary = cero
do i = 1, Nboulders
pos_ast_from_primary = pos_ast_from_primary + mu_ast_arr(i) * pos_from_primary(i,:) ! Posición del asteroide
vel_ast_from_primary = vel_ast_from_primary + mu_ast_arr(i) * vel_from_primary(i,:) ! Velocidad del asteroide
acc_ast_from_primary = acc_ast_from_primary + mu_ast_arr(i) * acc_from_primary(i,:) ! Aceleración del asteroide
end do
if (use_boulders) theta_ast_from_primary = atan2(pos_ast_from_primary(2), pos_ast_from_primary(1)) ! Ángulo del asteroide
!!! Mensaje
if (use_screen .and. use_boulders) then
write (*,*) " Centro de masas desde m0: [x, y, vx, vy, ax, ay, mass]"
write (*,f133) " CM", pos_ast_from_primary / unit_dist, &
& vel_ast_from_primary / unit_vel, &
& acc_ast_from_primary / unit_acc, &
& asteroid_mass / unit_mass
write (*,*) ACHAR(5)
end if
!! Baricentricas
!!! Inicializamos asteroide
pos_ast_arr(0,:) = - pos_ast_from_primary
vel_ast_arr(0,:) = - vel_ast_from_primary
acc_ast_arr(0,:) = - acc_ast_from_primary
theta_ast_arr(0) = mod(theta_ast_from_primary + pi, twopi)
dist_ast_arr(0) = sqrt(pos_ast_arr(0,1)*pos_ast_arr(0,1) + pos_ast_arr(0,2)*pos_ast_arr(0,2))
do i = 1, Nboulders
pos_ast_arr(i,:) = pos_from_primary(i,:) - pos_ast_from_primary
vel_ast_arr(i,:) = vel_from_primary(i,:) - vel_ast_from_primary
acc_ast_arr(i,:) = acc_from_primary(i,:) - acc_ast_from_primary
theta_ast_arr(i) = atan2(pos_ast_arr(i,2), pos_ast_arr(i,1))
dist_ast_arr(i) = sqrt(pos_ast_arr(i,1)*pos_ast_arr(i,1) + pos_ast_arr(i,2)*pos_ast_arr(i,2))
end do
!!! Mensaje
if (use_screen .and. use_boulders) then
write (*,*) " Baricentricas: [x, y, vx, vy, ax, ay, mass, distance, theta]"
do i = 0, Nboulders
write (*,f233) i, &
& pos_ast_arr(i,:) / unit_dist, &
& vel_ast_arr(i,:) / unit_vel, &
& acc_ast_arr(i,:) / unit_acc, &
& mass_ast_arr(i) / unit_mass, &
& dist_ast_arr(i) / unit_dist, &
& theta_ast_arr(i) / radian
end do
write (*,*) ACHAR(5)
end if
! Define asteroid radius
if (use_boulders) then
asteroid_radius = maxval(dist_ast_arr(1:Nboulders) + radius_ast_arr(1:Nboulders)) ! Radio del asteroide
else
asteroid_radius = radius_primary
end if
!! Mensaje
if (use_screen .and. use_boulders) then
write (*,f13) "Masa total de asteroide :", asteroid_mass / unit_mass, "[kg]"
write (*,f13) "Radio efectivo del asteroide:", asteroid_radius / unit_dist, "[km]"
write (*,*) ACHAR(5)
end if
! Angular momentum and Inertia
asteroid_angmom = cero
asteroid_inertia = cero
if (use_boulders) then
do i = 0, Nboulders
aux_real = 0.4d0 * mass_ast_arr(i) * radius_ast_arr(i)**2 ! Inertia Sphere
asteroid_angmom = asteroid_angmom + mass_ast_arr(i) * cross2D(pos_ast_arr(i,:), vel_ast_arr(i,:)) ! Traslacional
asteroid_angmom = asteroid_angmom + aux_real * asteroid_omega ! Rotacional (Sphere)
asteroid_inertia = asteroid_inertia + aux_real + mass_ast_arr(i) * dist_ast_arr(i)**2 ! Sphere + Steiner
end do
else
asteroid_inertia = 0.4d0 * mass_primary * radius_primary**2 ! Sphere
asteroid_angmom = asteroid_inertia * asteroid_omega ! Spin
end if
!! Mensaje
if (use_screen) then
write (*,f13) "Momento angular total :", asteroid_angmom / unit_mass / (unit_dist**2) * unit_time, "[kg km^2 / day]"
write (*,f13) "Momento inercia asteroide:", asteroid_inertia / (unit_mass * unit_dist**2), "[kg km^2]"
write (*,*) "Check:"
write (*,f13) " L / (I * omega):", asteroid_angmom / asteroid_inertia / asteroid_omega
write (*,f13) " Relative error :", abs(asteroid_omega - (asteroid_angmom / asteroid_inertia)) / asteroid_omega
write (*,*) ACHAR(5)
end if
! Asteroide, desde centro del sistema
asteroid_pos = cero
asteroid_vel = cero
asteroid_acc = cero
asteroid_theta = cero
asteroid_theta_correction = cero ! Corrección angular
do i = 0, Nboulders
asteroid_pos = asteroid_pos + mass_ast_arr(i) * pos_ast_arr(i,:)
asteroid_vel = asteroid_vel + mass_ast_arr(i) * vel_ast_arr(i,:)
end do
asteroid_pos = asteroid_pos / asteroid_mass ! rcm = sum_i m_i * r_i / M
asteroid_vel = asteroid_vel / asteroid_mass ! vcm = sum_i m_i * v_i / M
!!!! Mensaje
if (use_screen) then
write (*,*) "Centro de masas del asteroide:"
write (*,f1331) " [x, y] : ", asteroid_pos / unit_dist, "[km]"
write (*,f1331) " [vx, vy]: ", asteroid_vel / unit_vel, "[km/day]"
write (*,*) ACHAR(5)
end if
!! Check y Centrado
if (hard_center) then
if (any(abs(asteroid_pos) > cero)) then
if (use_screen) write (*,*) " - Se centrarán las posiciones para que el asteroide esté en el origen."
do i = 0, Nboulders
pos_ast_arr(i,:) = pos_ast_arr(i,:) - asteroid_pos
end do
asteroid_pos = cero
end if
if (any(abs(asteroid_vel) > cero)) then
if (use_screen) write (*,*) " - Se centrarán las velocidades para que el asteroide esté en el origen."
do i = 0, Nboulders
vel_ast_arr(i,:) = vel_ast_arr(i,:) - asteroid_vel
end do
asteroid_vel = cero
end if
end if
! EFECTOS EXTERNOS
if (use_screen) then
write (*,*) ACHAR(5)
write (*,*) ("---------- Efectos ex/internos ----------")
write (*,*) ACHAR(5)
end if
!! Variación en masa o en omega (funciones del tiempo)
mass_exp_damping_time = cero !!! Deprecado
if ((abs(omega_linear_damping_time) > tini) .and. (omega_linear_damping_time < infinity)) then
if (use_explicit_method) then
write (*,*) ACHAR(10)
write (*,*) "ERROR: No se puede usar el método explícito con tau_o finito."
write (*,f13) "tau_o [Prot]:", omega_linear_damping_time * unit_time / asteroid_rotational_period
stop 1
end if
if (.not. use_boulders) then
write (*,*) "WARNING: Omega damping has no effect without boulders. It won't be used"
omega_linear_damping_time = infinity
omega_linear_damping_slope = cero
else
omega_linear_damping_time = omega_linear_damping_time * unit_time
omega_linear_damping_slope = - asteroid_omega / (omega_linear_damping_time - initial_time)
if (use_screen) then
write (*,*) "Explicit omega linear damping"
write (*,f13) " tau_o :", omega_linear_damping_time / asteroid_rotational_period, "[Prot]"
end if
end if
else
omega_linear_damping_time = infinity
omega_linear_damping_slope = cero
end if
if ((abs(omega_exp_damping_time) > tini) .and. (omega_exp_damping_time < infinity)) then
if (use_explicit_method) then
write (*,*) ACHAR(10)
write (*,*) "ERROR: No se puede usar el método explícito con tau_o finito."
write (*,f13) "tau_o [Prot]:", omega_exp_damping_time * unit_time / asteroid_rotational_period
stop 1
end if
if (.not. use_boulders) then
write (*,*) "WARNING: Omega damping has no effect without boulders. It won't be used"
omega_exp_damping_time = infinity
else
omega_exp_damping_time = omega_exp_damping_time * unit_time
if (use_screen) then
write (*,*) "Explicit omega exponential damping"
write (*,f13) " tau_o :", omega_exp_damping_time / asteroid_rotational_period, "[Prot]"
end if
end if
else
omega_exp_damping_time = infinity
end if
if ((abs(mass_exp_damping_time) > tini) .and. (mass_exp_damping_time < infinity)) then
if (use_explicit_method) then
write (*,*) ACHAR(10)
write (*,*) "ERROR: No se puede usar el método explícito con tau_m finito."
write (*,f13) "tau_m [Prot]:", mass_exp_damping_time * unit_time / asteroid_rotational_period
stop 1
end if
mass_exp_damping_time = mass_exp_damping_time * unit_time
if (use_screen) then
write (*,*) "Explicit mass exponential damping"
write (*,f13) " tau_m :", mass_exp_damping_time / asteroid_rotational_period, "[Prot]"
end if
else
mass_exp_damping_time = infinity
end if
!!! Check not both omega dampings
if (omega_exp_damping_time < infinity .and. omega_linear_damping_time < infinity) then
write (*,*) ACHAR(10)
write (*,*) "ERROR: No se puede usar ambos decaimientos de omega (linear and exp) finitos."
stop 1
end if
!!! Check que no esté torque también
if (use_torque .and. ((omega_exp_damping_time < infinity) .or. (omega_linear_damping_time < infinity))) then
write (*,*) ACHAR(10)
write (*,*) "ERROR: No se puede usar torque y tau_o finito."
stop 1
end if
!!!
!! Stokes
if (use_stokes) then
call set_stokes_C_and_alpha(stokes_a_damping_time, stokes_e_damping_time, stokes_C, stokes_alpha)
stokes_a_damping_time = stokes_a_damping_time * unit_time
stokes_e_damping_time = stokes_e_damping_time * unit_time
stokes_charac_time = stokes_charac_time * unit_time
!!! Mensaje
if (use_screen) then
write (*,*) "Stokes"
write (*,f13) " t_stokes: ", stokes_charac_time / unit_time, "[days]"
write (*,f13) " C : ", stokes_C
write (*,f13) " alpha : ", stokes_alpha
end if
else ! Just to be sure
stokes_a_damping_time = infinity
stokes_e_damping_time = infinity
stokes_charac_time = cero
end if
!! Torque
if ((.not. use_boulders) .and. use_torque) then
if (use_screen) write (*,*) "WARNING: Torque has no effect without boulders. It won't be used"
use_torque = .False.
end if
!! Mensaje !
if (use_screen) then
if (use_naive_stokes) then !!!! Naive-Stokes
write (*,*) "Naive-Stokes (drag radial)"
write (*,f13) " Eta :", drag_coefficient
write (*,f13) " t_naive:", stokes_charac_time / unit_time, "[days]"
end if
if (use_J2) then
write (*,*) "Geo-Potential (J2)"
write (*,f13) " J2 :", J2_coefficient !!!! Geo-Potential (J2)
end if
if (use_torque) write (*,*) "Torque from particles to asteroid ACTIVATED"
if (.not. any((/use_stokes, use_naive_stokes, use_J2, use_torque, &
& omega_linear_damping_time < infinity, &
& omega_exp_damping_time < infinity, &
& mass_exp_damping_time < infinity/))) then
write (*,*) "No se aplicarán efectos ex/internos."
end if
end if
!!!!!!!!!!!!!!!!!!!!! MAPA Potencial y Aceleraciones !!!!!!!!!!!!!!!!!!!!!!
if (use_potential_map) then
if (use_screen) then
write (*,*) ACHAR(5)
write (*,*) "---------- MAPA potencial (y aceleracion) ----------"
write (*,*) ACHAR(5)
write (*,*) "Creando mapa de potencial..."
end if
call create_map(Nboulders, &
& map_grid_size_x, map_grid_size_y, &
& map_min_x, map_max_x, &
& map_min_y, map_max_y, &
& mass_ast_arr,pos_ast_arr,vel_ast_arr, &
& mapfile)
if (use_screen) then
write (*,*) "Guardado en el archivo: ", trim(mapfile)
write (*,*) ACHAR(5)
end if
end if
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (use_screen) then
write (*,*) ACHAR(5)
write (*,*) "---------- Preparando partículas ----------"
write (*,*) ACHAR(5)
end if
! Particle(s)
Nparticles = 0
!! Partiles?
if (use_single_particle) Nparticles = Nparticles + 1
if (use_particlesfile) then
if (use_screen) write (*,*) "Leyendo partículas desde archivo: ", trim(particlesfile)
!!!! Formato: [mass, a, e, M, w, (MMR)]
call read_columns_file(particlesfile, aux_particles_arr)
Narticles_in_partfile = size(aux_particles_arr, 1)
if (use_screen) then
write (*,f12) " Se han leído ", Narticles_in_partfile, " filas."
write (*,f12) " Se han leído ", size(aux_particles_arr, 2), " columnas."
end if
! [Remember to free memory later...]
else
Narticles_in_partfile = 0
end if
!!! Sumamos
Nparticles = Nparticles + Narticles_in_partfile
!!!! Redefine Chaos (needed to allocate arrays)
use_chaos = (use_chaosfile .or. (use_datascreen .and. (Nparticles .eq. 1))) .or. use_chaos
!! Allocate
if (Nparticles > 0) then
call allocate_particles(Nparticles)
else
write (*,*) ACHAR(10)
write (*,*) "ERROR: No hay partículas para integrar."
stop 1
end if
!! Redefine OMP threads if necessary. Lower equal to particle number
if ((use_parallel) .and. (Nparticles < my_threads)) then
my_threads = Nparticles
if (use_screen) then
write (*,f12) "WARNING: Se reducen los threads a ", my_threads
write (*,*) ACHAR(5)
end if
!$ call omp_set_num_threads(my_threads)
end if
!! Create Index
do i = 1, Nparticles
particles_index(i) = i
sorted_particles_index(i) = i
end do
if (use_particlesfile) then
particles_mass(:Narticles_in_partfile) = aux_particles_arr(:,1) * unit_mass ! Masa
particles_elem(:Narticles_in_partfile,1) = aux_particles_arr(:,2) * unit_dist ! a
particles_elem(:Narticles_in_partfile,2) = aux_particles_arr(:,3) ! e
particles_elem(:Narticles_in_partfile,3) = aux_particles_arr(:,4) * radian ! M
particles_elem(:Narticles_in_partfile,4) = aux_particles_arr(:,5) * radian ! w
if (size(aux_particles_arr, 2) > 5) then
!$OMP PARALLEL DEFAULT(SHARED) &
!$OMP PRIVATE(i)
!$OMP DO SCHEDULE (STATIC)
do i = 1, Narticles_in_partfile
if (aux_particles_arr(i,6) > tini) then
particles_MMR(i) = aux_particles_arr(i,6) ! MMR
particles_elem(i,1) = particles_MMR(i)**(2/3.) * asteroid_a_corot ! a
else
particles_MMR(i) = (particles_elem(i,1) / asteroid_a_corot)**(1.5) ! MMR
end if
end do
!$OMP END DO
!$OMP END PARALLEL
else
particles_MMR(:Narticles_in_partfile) = (particles_elem(:Narticles_in_partfile,1) / asteroid_a_corot)**(1.5)
end if
!! Deallocatamos
deallocate(aux_particles_arr)
end if
if (use_single_particle) then
if (use_elements_output) particles_index(Nparticles) = simulation_number
!! Masa
particles_mass(Nparticles) = single_part_mass * unit_mass ! Masa
!! Elementos orbitales
particles_elem(Nparticles,1) = single_part_elem_a * unit_dist ! a
particles_elem(Nparticles,2) = single_part_elem_e ! e
particles_elem(Nparticles,3) = single_part_elem_M * radian ! M
particles_elem(Nparticles,4) = single_part_elem_w * radian ! w
if (single_part_MMR > tini) then
particles_elem(Nparticles,1) = single_part_MMR**(2/3.) * asteroid_a_corot
particles_MMR(Nparticles) = single_part_MMR
else
particles_MMR(Nparticles) = (particles_elem(Nparticles,1) / asteroid_a_corot)**(1.5)
end if
end if
!! Crear vector de coordenadas
aux_real_arr6 = cero
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP PRIVATE(i,aux_real_arr6) &
!$OMP SHARED(Nparticles,asteroid_mass,particles_mass,particles_elem,particles_coord)
!$OMP DO SCHEDULE (STATIC)
do i = 1, Nparticles
!!! Coordenadas y vectores
call coord(asteroid_mass + particles_mass(i), & ! Masa
& particles_elem(i,1), particles_elem(i,2), cero, & ! a, e, i
& particles_elem(i,3), particles_elem(i,4), cero, & ! M, w, Omega
& aux_real_arr6)
particles_coord(i,:) = (/aux_real_arr6(1:2), aux_real_arr6(4:5)/) ! [x, y, vx, vy]
end do
!$OMP END DO
!$OMP END PARALLEL
!! Crear vector distancias
particles_dist = sqrt(sum(particles_coord(:,1:2) * particles_coord(:,1:2), 2)) ! sqrt(x^2 + y^2)
!! Chaos and Outcome
particles_outcome = 0
if (use_chaos) then
particles_max_a = cero
particles_min_a = infinity
particles_max_e = cero
particles_min_e = infinity
particles_times = cero
end if
particles_hexit = 0
!!! Redefine logicals
if (all(particles_mass < tini)) use_merge = .False. ! No merge if no mass
use_single_particle = Nparticles .eq. 1
if (use_single_particle) use_elements = .True.
!! Mensaje
if (use_screen) then
if (use_single_particle) then
write (*,*) "Partícula simple:"
write (*,f13) " Masa:", particles_mass(Nparticles) / unit_mass, "[kg]"
write (*,*) " Elementos orbitales:"
write (*,f13) " a :", particles_elem(Nparticles,1) / unit_dist, "[km]"
write (*,f13) " e :", particles_elem(Nparticles,2)
write (*,f13) " M :", particles_elem(Nparticles,3) / radian, "[deg]"
write (*,f13) " w :", particles_elem(Nparticles,4) / radian, "[deg]"
write (*,f13) " MMR :", particles_MMR(Nparticles)
write (*,f13) " Periodo:", twopi * sqrt(particles_elem(Nparticles,1)**3 / &
& (Gasteroid_mass + particles_mass(Nparticles))) / unit_time, "[day]"
write (*,*) " Coordenadas:"
write (*,f13) " x :", particles_coord(Nparticles,1) / unit_dist, "[km]"
write (*,f13) " y :", particles_coord(Nparticles,2) / unit_dist, "[km]"
write (*,f13) " vx :", particles_coord(Nparticles,3) / unit_vel, "[km/day]"
write (*,f13) " vy :", particles_coord(Nparticles,4) / unit_vel, "[km/day]"
write (*,f13) " dist:", particles_dist(Nparticles) / unit_dist, "[km]"
else
write (*,f12) "Cantidad total de partículas:", Nparticles
end if
write (*,*) ACHAR(5)
end if
!! Definimos Tipo 1 o Tipo 2, dependiendo si tienen masa
Nparticles_type1 = count(particles_mass > cero)
Nparticles_type2 = count(particles_mass <= cero)
! ! ! Reordenamos las particulas, dependiendo si tienen masa o no [NO NECESSARY]
! ! if ((.not. use_single_particle) .and. (Nparticles_type1 > 1)) then
! ! call argsort(particles_mass, sorted_particles_index)
! ! do i = 1, Nparticles
! ! particles_mass(i) = particles_mass(sorted_particles_index(i))
! ! particles_elem(i,:) = particles_elem(sorted_particles_index(i),:)
! ! particles_coord(i,:) = particles_coord(sorted_particles_index(i),:)
! ! particles_dist(i) = particles_dist(sorted_particles_index(i))
! ! particles_MMR(i) = particles_MMR(sorted_particles_index(i))
! ! end do
! ! else
! ! sorted_particles_index = particles_index
! ! end if
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!! FIN DE CÁLCULOS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Ntotal = 1 + Nboulders + Nparticles ! Número total de cuerpos a integra
Nactive = Nparticles ! Número de cuerpos activos (no colisionados o escapados)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!! INTEGRACIÓN !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Mensaje
if (use_screen) then
write (*,*) ACHAR(5)
write (*,*) "---------- Preparando integración ----------"
write (*,*) ACHAR(5)
end if
! Escape/Colisión
if (min_distance < cero) then
min_distance = asteroid_radius * abs(min_distance)
else if (min_distance < tini) then
min_distance = asteroid_radius
else
min_distance = min_distance * unit_dist
end if
if (max_distance < cero) then
max_distance = asteroid_radius * abs(max_distance)
else
max_distance = max_distance * unit_dist
end if
if (max_distance <= min_distance) then
write (*,*) ACHAR(10)
write (*,*) "ERROR: rmax <= rmin"
stop 1
end if
if (use_screen) then
write (*,*) "Condición escape/colisión"
write (*,f13) " rmin : ", min_distance / unit_dist, "[km] =", min_distance / asteroid_radius, "[Rast]"
write (*,f13) " rmax : ", max_distance / unit_dist, "[km] =", max_distance / asteroid_radius, "[Rast]"
if (use_merge) then
write (*,*) " Las colisiones se resolverán como mergers al asteroide."
else
write (*,*) " Las colisiones NO se resolverán."
end if
write (*,*) ACHAR(5)
end if
!!!!!!!! TIEMPOS !!!!!!!
! Tiempos de integración
initial_time = initial_time * unit_time
if (final_time < cero) then
final_time = abs(final_time) * asteroid_rotational_period
else
final_time = final_time * unit_time
end if
if (initial_time >= final_time) then
write (*,*) ACHAR(10)
write (*,*) "ERROR: t0 >= tf"
stop 1
end if
!! Timesteps
output_timestep = output_timestep * unit_time
min_timestep = min_timestep * unit_time
!! Output times
call set_output_times(initial_time, final_time, output_number, output_timestep, case_output_type, output_times)
!! TOMFILE
if (use_tomfile) then
!! En este caso, leeremos los tiempos desde un archivo
if (use_screen) write (*,*) "Leyendo tiempos desde el archivo TOM: ", trim(tomfile)
call read_tomfile(initial_time / unit_time, final_time / unit_time, tom_times, tom_deltaomega, tom_deltamass, tomfile) ! Read LOOP checkpoints
tom_total_number = size(tom_times, 1)
!!! Unidades
tom_times = tom_times * unit_time
if (allocated(tom_deltaomega)) tom_deltaomega = tom_deltaomega / unit_time
if (allocated(tom_deltamass)) tom_deltamass = tom_deltamass * unit_mass
!!! Condicion inicial (y final)
tom_times(1) = initial_time
tom_times(tom_total_number) = final_time
if (allocated(tom_deltaomega)) then
tom_deltaomega(1) = cero
tom_deltaomega(tom_total_number) = cero
end if
if (allocated(tom_deltamass)) then
tom_deltamass(1) = cero
tom_deltamass(tom_total_number) = cero
end if
!!! Mensaje !
if (use_screen) then
if (allocated(tom_deltamass)) then
write (*,*) " Se han leído 3 columnas: t, Delta_omega, Delta_m"
else if (allocated(tom_deltaomega)) then
write (*,*) " Se han leído 2 columnas: t, Delta_omega"
else
write (*,*) " Se ha leído 1 columna: t"
end if
end if
!! Ahora debemos combinar los tiempos de TOM con los tiempos de Output, y crear un nuevo vector de tiempos Checkpoints
call merge_sort_and_unique(tom_times, output_times, &
& checkpoint_is_tom, checkpoint_is_output, &
& checkpoint_times, checkpoint_number)
if (allocated(tom_deltaomega) .and. (.not. use_boulders)) then
if (use_screen) write (*,*) "WARNING: No tiene sentido Delta_omega sin boulders. Se ignorará."
deallocate(tom_deltaomega)
end if
else
!! En este caso, los tiempos de check son los mismos que los de LOOP
checkpoint_number = output_number
allocate(checkpoint_times(checkpoint_number))
allocate(checkpoint_is_output(checkpoint_number))
allocate(checkpoint_is_tom(checkpoint_number))
checkpoint_times = output_times
checkpoint_is_output = .True.
checkpoint_is_tom = .False.
tom_total_number = 0
end if
! Variable temporal (para integración)
time = initial_time ! Tiempo actual
timestep = output_times(1) - initial_time ! Paso de tiempo inicial
min_timestep = max(min(min_timestep, output_timestep), tini) ! Paso de tiempo mínimo
adaptive_timestep = asteroid_rotational_period*0.01d0 ! Paso de tiempo adaptativo inicial: 1% del periodo de rotación
!! Mensaje
if (use_screen) then
write (*,*) "Tiempos:"
write (*,f13) " t0 : ", initial_time / asteroid_rotational_period, "[Prot] = ", &
& initial_time / unit_time, "[day]"
write (*,f13) " tf : ", final_time / asteroid_rotational_period, "[Prot] = ", &
& final_time / unit_time, "[day]"
write (*,f13) " dt_out: ", output_timestep / asteroid_rotational_period, "[Prot] = ", &
& output_timestep / unit_time, "[day]"
write (*,f13) " dt_min: ", min_timestep / asteroid_rotational_period, "[Prot] = ", &
& min_timestep / unit_time, "[day]"
write (*,f12) " n_out : ", output_number
write (*,*) ACHAR(5)
end if
!!!!!!!! VECTOR A INTEGRAR !!!!!!!
!!!! Inicializamos vector
if (use_version_1 .or. (.not. use_boulders)) then
!!!!! Version 1: [x0, y0, vx0, vy0, x1, y1, vx1, vy1, ...]
allocate(parameters_arr(4 * Ntotal))
allocate(parameters_arr_new(4 * Ntotal))
do i = 0, Nboulders
parameters_arr(1 + 4 * i) = pos_ast_arr(i,1)
parameters_arr(2 + 4 * i) = pos_ast_arr(i,2)
parameters_arr(3 + 4 * i) = vel_ast_arr(i,1)
parameters_arr(4 + 4 * i) = vel_ast_arr(i,2)
end do
!$OMP PARALLEL DEFAULT(SHARED) &
!$OMP PRIVATE(i)
!$OMP DO SCHEDULE (STATIC)
do i = 1, Nparticles
parameters_arr(1 + 4 * (i + Nboulders)) = particles_coord(i,1) ! xP
parameters_arr(2 + 4 * (i + Nboulders)) = particles_coord(i,2) ! yP
parameters_arr(3 + 4 * (i + Nboulders)) = particles_coord(i,3) ! vPx
parameters_arr(4 + 4 * (i + Nboulders)) = particles_coord(i,4) ! vPy
end do
!$OMP END DO
!$OMP END PARALLEL
first_particle = 1 + 4 * (Nboulders + 1)
else
!!!!! Version 2: [theta, omega, xA, yA, vxA, vyA, Part...]
allocate(parameters_arr(6 + 4 * Nparticles))
allocate(parameters_arr_new(6 + 4 * Nparticles))
parameters_arr(1) = asteroid_theta
parameters_arr(2) = asteroid_omega
parameters_arr(3:4) = asteroid_pos
parameters_arr(5:6) = asteroid_vel
!$OMP PARALLEL DEFAULT(SHARED) &
!$OMP PRIVATE(i)
!$OMP DO SCHEDULE (STATIC)
do i = 1, Nparticles
parameters_arr(3 + 4 * i) = particles_coord(i,1) ! xP
parameters_arr(4 + 4 * i) = particles_coord(i,2) ! yP
parameters_arr(5 + 4 * i) = particles_coord(i,3) ! vPx
parameters_arr(6 + 4 * i) = particles_coord(i,4) ! vPy
end do
!$OMP END DO
!$OMP END PARALLEL
first_particle = 7
end if
!! Define last particle ( y -> parameters(:last_particle) )
last_particle = first_particle + 4 * Nparticles - 1
! CHECKS
if (use_screen) then
write (*,*) ACHAR(5)
write (*,*) "---------- CHECKS ----------"
write (*,*) ACHAR(5)
end if
!!!! Checkeo rápido
!!!! Check. Do I have to work?
if (all(particles_MMR <= tini)) then
if (use_screen) then
write (*,*) ACHAR(10)
write (*,*) "Initial particles condition a=0. Nothing to do here."
write (*,*) "Saliendo."
end if
stop 1
end if
!!! Check workers
if (use_parallel) then
aux_integer = MIN(MAX(Nactive, 3), my_threads)
if (aux_integer .ne. my_threads) then