-
Notifications
You must be signed in to change notification settings - Fork 0
/
input_output.f90
2326 lines (1931 loc) · 78.9 KB
/
input_output.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
!******************************************************************************
! MODULE: input_output
!******************************************************************************
!
! DESCRIPTION:
!> @brief Module that contains all the routines linked to reading input files
!! or writing output files. \n\n
!!
!! Input files tends to be named *.in
!! Output files tends to be named *.out
!! Temporary files that are overwritten at each timestep are named *.tmp
!
!******************************************************************************
module input_output
use iso_fortran_env
implicit none
contains
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author
!> Christophe Cossou
!
!> @date 2014
!
! DESCRIPTION:
!> @brief Write information in an output file, notably the commit and branch of the compiled binary
!! Also show if the current version had uncommitted modification that can't
!! be traced.
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine write_general_infos()
use global_variables
use git_infos
implicit none
character(len=80) :: filename = 'info.out'
open(10, file=filename)
write(10,'(a)') '!----------------------------'
write(10,'(a)') '! Nautilus Version |'
write(10,'(a)') '!----------------------------'
write(10,'(a,a)') 'branch = ', trim(branch)
write(10,'(a,a)') 'commit = ', trim(commit)
write(10,'(a,a)') '!', trim(modifs)
write(10,'(a)') ""
write(10,'(a)') '!----------------------------'
write(10,'(a)') '! General infos |'
write(10,'(a)') '!----------------------------'
write(10,'(a,i0)') 'Maximum number of non-zeros values in jacobian = ', nb_nonzeros_values
close(10)
end subroutine write_general_infos
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author
!> Franck Hersant
!
!> @date 2000
!
! DESCRIPTION:
!> @brief Write the list of species and the corresponding index in an
!! output file 'species.out'.
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine write_species()
use global_variables
implicit none
! Locals
integer :: i
open(10, file='species.out')
! Write 'ggo_spec.d': 5 columns of numbered species=====================
write(10,'(5(I4,")",1X,A11,1X))') (I,species_name(I),I=1,nb_species)
close(10)
return
end subroutine write_species
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author
!> Christophe Cossou
!
!> @date 2014
!
! DESCRIPTION:
!> @brief Write the list of elemental species with their abundances and mass.
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine write_elemental_abundances(filename, el_abundances)
use global_variables
implicit none
! Input
character(len=*), intent(in) :: filename !< [in] the name of the output file
real(double_precision), intent(in), dimension(NB_PRIME_ELEMENTS) :: el_abundances !< [in] Elemental abundances, either initial or current ones
! Locals
integer :: i
open(10, file=filename)
write(10, '(a)') '! Species name ; abundance (relative to H) ; mass (AMU)'
do i=1, NB_PRIME_ELEMENTS
write(10, '(a,es10.4e2, f8.3)') species_name(PRIME_ELEMENT_IDX(i)), el_abundances(i), elemental_mass(i)
enddo
close(10)
return
end subroutine write_elemental_abundances
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author
!> Franck Hersant & Christophe Cossou
!
!> @date 2000
!
! DESCRIPTION:
!> @brief Write all abundances for all species in an output file at each
!! output time. The total number of output files related to abundances
!! will be equal to the number of timestep, not equally spaced in time.\n\n
!! Output filename is of the form : abundances.000001.out
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine write_current_output(index)
! Writes 1D outputs
use global_variables
implicit none
! Input
integer, intent(in) :: index !<[in] The reference index of the current output
! Locals
character(len=80) :: filename_output
write(filename_output, '(a,i0.6,a)') 'abundances.',index,'.out'
open(UNIT=35, file=filename_output, form='unformatted')
write(35) current_time
write(35) gas_temperature(1:spatial_resolution), dust_temperature(1,1:spatial_resolution), &
H_number_density(1:spatial_resolution), visual_extinction(1:spatial_resolution), X_IONISATION_RATE
write(35) abundances(1:nb_species, 1:spatial_resolution)
close(35)
return
end subroutine write_current_output
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author
!> Franck Hersant
!
!> @date 2000
!
! DESCRIPTION:
!> @brief Write rates of all chemical reactions for the current timestep.
!! The total number of files will be equal to the total number of timesteps, the
!! routine being called at the end of each timestep.\n\n
!! Output filename is of the form : rates.000001.out
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine write_current_rates(index)
use global_variables
implicit none
! Input
integer, intent(in) :: index !<[in] The reference index of the current output
! Locals
character(len=80) :: filename_output
write(filename_output, '(a,i0.6,a)') 'rates.',index,'.out'
open(45, file=filename_output, form='unformatted')
write(45) reaction_rates_1D
close(45)
return
end subroutine write_current_rates
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author
!> Valentine Wakelam
!
!> @date 2014
!
! DESCRIPTION:
!> @brief Write the H2 and CO column density computed by the model - used
! for the self-shielding of H2 and CO from the UV photons
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine write_H2_CO_col_dens(index)
use global_variables
implicit none
! Input
integer, intent(in) :: index !<[in] The reference index of the current output
! Locals
character(len=80) :: filename_output
integer :: i
write(filename_output, '(a,i0.6,a)') 'col_dens.',index,'.out'
open(55, file=filename_output)
! Header
write(55,'(50a)') 'H column density (cm-2) H2 column density (cm-2) CO column density (cm-2) N2 column density (cm-2)'
do i=1,spatial_resolution
write(55,*) NH_z(i),NH2_z(i),NCO_z(i), NN2_z(i)
enddo
close(55)
return
end subroutine write_H2_CO_col_dens
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author
!> Franck Hersant
!
!> @date 2000
!
! DESCRIPTION:
!> @brief Write the total chemical composition of the actual timestep in
!! a file whose name is given as an input parameter. This allow to use the
!! same routine to write input, temporary and output files
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine write_abundances(filename)
use global_variables
implicit none
! Input
character(len=*), intent(in) :: filename !<[in] the name of the output file
! Locals
integer :: i
character(len=80) :: line_format
open(13, file=filename)
! Header
write(13,'(5(a,es10.3e2),a)') '!time =', current_time, ' s ; density = ', H_number_density, &
' part/cm^3 ; temperature=', gas_temperature,' K ; visual extinction = ', visual_extinction, &
' [mag] ; CR ionisation rate = ',CR_IONISATION_RATE,' s-1'
! To adapt the format in function of the 1D number of points
write(line_format,'(a,i0,a)') '(a," = ",', spatial_resolution, '(es12.5e2))'
do i=1,nb_species
write(13,line_format) trim(species_name(i)), abundances(i,1:spatial_resolution)
enddo
close(13)
return
end subroutine write_abundances
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author
!> Christophe Cossou
!
!> @date 2014
!
! DESCRIPTION:
!> @brief subroutine that write the simulation parameters into the file 'parameters.out'
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine write_parameters()
use global_variables
implicit none
character(len=80) :: filename = 'parameters.in'
character(len=80) :: cp_command
! Copy the old file into a *.bak version just in case
write(cp_command, '(5a)') 'cp ', trim(filename), ' ', trim(filename), '.bak'
call system(cp_command)
open(10, file=filename)
write(10,'(a)') "!# ------------------------------------------------"
write(10,'(a)') "!# Parameter file for various properties of the disk."
write(10,'(a)') "!# ------------------------------------------------"
write(10,'(a)') "!# blanck line or with spaces will be skipped."
write(10,'(a)') "!# In fact, the only lines that matter are non commented lines with a"
write(10,'(a)') "!# '=' character to distinguish the identificator and the value(s)"
write(10,'(a)') "!# (each value must be separated with at least one space."
write(10,'(a)') "!# Line must not be longer than 80 character, but comments can be far"
write(10,'(a)') "!# bigger than that, even on line with a parameter to read."
write(10,'(a)') ""
write(10,'(a)') "!*****************************"
write(10,'(a)') "!* Switch 2/3 phase model *"
write(10,'(a)') "!*****************************"
write(10,'(a)') ""
write(10,'(a,i0,a)') 'is_3_phase = ', is_3_phase, ' ! 0: 2 phase, 1: 3 phase'
write(10,'(a)') ""
write(10,'(a)') "!*****************************"
write(10,'(a)') "!* Switches *"
write(10,'(a)') "!*****************************"
write(10,'(a)') ""
write(10,'(a,i0,a)') 'preliminary_test = ', IS_TEST, ' ! Will or will not do comprehensive tests &
&before the simulation. Switch it off when lauching thousands or simulations'
write(10,'(a,i0,a)') 'is_structure_evolution = ', IS_STRUCTURE_EVOLUTION, ' ! If 1, physical structure properties evolve with &
&time, values come from structure_evolution.dat file that must exists'
write(10,'(a,a,a)') 'grain_temperature_type = ', trim(GRAIN_TEMPERATURE_TYPE), ' ! fixed, fixed_to_dust_size, gas,&
& table_evolv, table_1D or computed'
write(10,'(a)') '! fixed: Tgrain = initial_dust_temperature. All dust grains have same temperature;'
write(10,'(a)') '! fixed_to_dust_size = each grain have a fixed temperature defined in1D_grain_sizes.in or 0D_grain_sizes.in;'
write(10,'(a)') '! gas: Tgrain = Tgas ; '
write(10,'(a)') '! table_evolv: Tgrain is interpolated from structure_evolution.dat data file (5th optional column) ; '
write(10,'(a)') '! table_1D: Tgrain is read in the 1D_static. dat file (5th column) ; '
write(10,'(a)') '! computed: calculated from uv_flux and visual extinction by radiative equilibrium'
! write(10,'(a,i0,a)') 'is_dust_1D = ', is_dust_1D, ' ! Reading the grain abundance and the NH/AV factor in the 1D_static.dat file &
! &(mostly for disks)'
write(10,'(a,i0,a)') 'photo_disk = ', photo_disk, ' ! Computation of photodissociation rates for protoplanetary disks.'
write(10,'(a,i0,a)') 'is_grain_reactions = ', IS_GRAIN_REACTIONS, ' ! Accretion, grain surface reactions'
write(10,'(a,i0,a)') 'is_h2_adhoc_form = ', IS_H2_ADHOC_FORM, ' ! Ad hoc formation of H2 on grain surfaces (1=activated)'
write(10,'(a,i0,a)') 'is_h2_formation_rate = ', is_h2_formation_rate, ' ! h2 formation rates on surfaces from Bron et al: (2014)'
write(10,'(a,i0,a)') 'height_h2formation = ', height_h2formation, ' ! Spatial point above which B14s method is used. If 0 then &
&B14 is not used at all.'
write(10,'(a,i0,a)') 'is_absorption_h2 = ', is_absorption_h2, ' ! H2 self-shielding from Lee & Herbst (1996) (1=activated)'
write(10,'(a,i0,a)') 'is_absorption_co = ', is_absorption_co, ' ! CO self-shielding. (1: Lee & Herbst (1996), &
& 2: Visser et al. (2009)'
write(10,'(a,i0,a)') 'is_absorption_n2 = ', is_absorption_n2, ' ! N2 self-shielding from Li et al. (2013) (1=activated)'
write(10,'(a,i0,a)') 'is_photodesorb = ', is_photodesorb, &
' ! Switch to turn on the photodesorption of ices (default yield is 1e-4)'
write(10,'(a,i0,a)') 'is_crid = ', is_crid, &
' ! Switch to turn on the CRID (cosmic rays induced diffusion) mechanism'
write(10,'(a,i0,a)') 'is_er_cir = ', is_er_cir, &
' ! Switch to turn on Eley-Rideal and Complex Induced Reaction mechanisms (default=0: desactivated)'
write(10,'(a,i0,a)') 'grain_tunneling_diffusion = ', GRAIN_TUNNELING_DIFFUSION, &
' ! 0=thermal; For H,H2: 1=QM1; 2=QM2; 3=choose fastest'
write(10,'(a,i0,a)') 'modify_rate_flag = ', MODIFY_RATE_FLAG, ' ! 1=modify H; 2=modify H,H2, 3=modify all, -1=H+H only'
write(10,'(a,i0,a)') 'conservation_type = ', CONSERVATION_TYPE, ' ! 0=only e- conserved; 1=elem #1 conserved, 2=elem #1 & #2, etc'
!write(10,'(a,i0,a)') 'is_dust_MRN = ', is_dust_MRN, '! 0 = custom; 1 = MRN distribution; 2 = WD distribution. 0D mode only.'
write(10,'(a)') ""
write(10,'(a)') "!*****************************"
write(10,'(a)') "!* Number of active layers *"
write(10,'(a)') "!*****************************"
write(10,'(a)') ""
write(10,'(a,es10.3e2,a)') 'nb_active_lay = ',nb_active_lay, ' ! Number of active layers'
write(10,'(a)') ""
write(10,'(a)') "!******************************"
write(10,'(a)') "!* 0D or 1D *"
write(10,'(a)') "!******************************"
write(10,'(a)') "!(diffusion is for species, not the structure)"
write(10,'(a)') ""
write(10,'(a,a,a)') 'structure_type = ', trim(STRUCTURE_TYPE), ' ! 0D, 1D_diff, 1D_no_diff'
write(10,'(a,i0,a)') 'spatial_resolution = ', spatial_resolution, &
' ! Number of lines in 1D. If 1, we are in 0D, else, we are in 1D, with diffusion between gas boxes.'
write(10,'(a)') ""
write(10,'(a)') '!******************************************************'
write(10,'(a)') '!* Use single-grain or multi-grain mode *'
write(10,'(a)') '!******************************************************'
write(10,'(a)') ""
write(10,'(a,i0,a)') 'multi_grain = ', multi_grain, ' ! 1 = multi-grain; 0 = single-grain. &
& If 1, then the grain parameters are read in 0D/1D_grain_sizes.in files.'
write(10,'(a)') ""
write(10,'(a)') "!*****************************"
write(10,'(a)') "!* Gas phase parameters *"
write(10,'(a)') "!*****************************"
write(10,'(a)') ""
write(10,'(a,es10.3e2,a)') 'initial_gas_density = ', initial_gas_density, ' ! initial gas density [part/cm-3]'
write(10,'(a,es10.3e2,a)') 'initial_gas_temperature = ', initial_gas_temperature, ' ! initial gas temperature [K]'
write(10,'(a,es10.3e2,a)') 'initial_visual_extinction = ', INITIAL_VISUAL_EXTINCTION, ' ! initial visual extinction'
write(10,'(a,es10.3e2,a)') 'cr_ionisation_rate = ', CR_IONISATION_RATE, ' ! cosmic ray ionisation rate [s-1] (standard=1.3e-17)'
write(10,'(a,es10.3e2,a)') 'x_ionisation_rate = ', X_IONISATION_RATE, ' ! Ionisation rate due to X-rays [s-1]'
write(10,'(a,es10.3e2,a)') 'uv_flux = ', UV_FLUX, ' ! Scale factor for the UV flux, in unit of the reference flux (1.=nominal)'
write(10,'(a)') ""
write(10,'(a)') "!*****************************"
write(10,'(a)') "!* Grain parameters *"
write(10,'(a)') "!*****************************"
write(10,'(a)') ""
write(10,'(a,es10.3e2,a)') 'initial_dust_temperature = ', initial_dust_temperature, ' ! initial dust temperature [K]&
& when grain_temperature_type=fixed'
write(10,'(a,es10.3e2,a)') 'initial_dtg_mass_ratio = ', initial_dtg_mass_ratio, ' ! dust-to-gas ratio by mass'
write(10,'(a,es10.3e2,a)') 'sticking_coeff_neutral = ', sticking_coeff_neutral, ' ! sticking coeff for neutral species'
write(10,'(a,es10.3e2,a)') 'sticking_coeff_positive = ', sticking_coeff_positive, ' ! sticking coeff for positive species'
write(10,'(a,es10.3e2,a)') 'sticking_coeff_negative = ', sticking_coeff_negative, ' ! sticking coeff for negative species'
write(10,'(a,es10.3e2,a)') 'grain_density = ', GRAIN_DENSITY, ' ! mass density of grain material'
write(10,'(a,es10.3e2,a)') 'grain_radius = ', grain_radius, ' ! grain radius [cm]'
write(10,'(a,es10.3e2,a)') 'diffusion_barrier_thickness = ', DIFFUSION_BARRIER_THICKNESS, ' ! Barrier thickness [cm]'
write(10,'(a,es10.3e2,a)') 'surface_site_density = ', SURFACE_SITE_DENSITY, ' ! site density on one grain [cm-2]'
write(10,'(a,es10.3e2,a)') 'diff_binding_ratio_surf = ', DIFF_BINDING_RATIO_SURF, &
' ! Ratio used to compute the DIFFUSION_BARRIER from the BINDING_ENERGY if not known (surface species)'
write(10,'(a,es10.3e2,a)') 'diff_binding_ratio_mant = ', DIFF_BINDING_RATIO_MANT, &
' ! Ratio used to compute the DIFFUSION_BARRIER from the BINDING_ENERGY if not known (mantle species)'
write(10,'(a,es10.3e2,a)') 'chemical_barrier_thickness = ', CHEMICAL_BARRIER_THICKNESS, &
' ! grain reaction activation energy barrier width. [cm]'
write(10,'(a,es10.3e2,a)') 'cr_peak_grain_temp = ', CR_PEAK_GRAIN_TEMP, ' ! peak grain temperature [K] (CR heating)'
write(10,'(a,es10.3e2,a)') 'cr_peak_duration = ', CR_PEAK_DURATION, ' ! duration [s] of peak grain temperature'
write(10,'(a,es10.3e2,a)') 'Fe_ionisation_rate = ', FE_IONISATION_RATE, ' ! (cosmic) Fe-ion--grain encounter [s-1 grain-1] '
write(10,'(a,es10.3e2,a)') '!! (for 0.1 micron grain) For cosmic photo desorptions, only Fe-ions are efficient to heat grains. '
write(10,'(a,es10.3e2,a)') 'vib_to_dissip_freq_ratio = ', VIB_TO_DISSIP_FREQ_RATIO, &
' ! [no unit] The ratio of the surface-molecule bond frequency to the frequency at'
write(10,'(a)') '!! which energy is lost to the grain surface. Used for the RRK (Rice Ramsperger-Kessel) desorption mechanism'
write(10,'(a)') '!! (see Garrod el al. 2007 for more). Assumed to be 1% by default.'
write(10,'(a,es10.3e2,a)') 'ED_H2 = ', ED_H2, &
' ! H2 binding energy over itself. Used for the desorption encounter mechanism. in K. '
write(10,'(a)') ""
write(10,'(a)') "!*****************************"
write(10,'(a)') "!* Integration and Outputs *"
write(10,'(a)') "!*****************************"
write(10,'(a)') ""
write(10,'(a,es10.3e2,a)') 'start_time = ', START_TIME/YEAR, ' ! [yrs] first output time'
write(10,'(a,es10.3e2,a)') 'stop_time = ', STOP_TIME/YEAR, ' ! [yrs] last output time'
write(10,'(a,i0,a)') 'nb_outputs = ', NB_OUTPUTS, ' ! Total number of outputs (used for linear or log spaced outputs)'
write(10,'(a,a,a)') 'output_type = ', trim(OUTPUT_TYPE), ' ! linear, log'
write(10, '(a)') '! linear: Output times are linearly spaced'
write(10, '(a)') '! log : Outputs times are log-spaced'
write(10,'(a,es10.3e2, a)') 'relative_tolerance = ',RELATIVE_TOLERANCE, ' ! Relative tolerance of the solver'
write(10,'(a,es10.3e2,a)') 'minimum_initial_abundance = ', MINIMUM_INITIAL_ABUNDANCE, ' ! default minimum initial &
&fraction abundance'
close(10)
end subroutine write_parameters
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author
!> Wasim Iqbal
!
!> @date 2017
!
! DESCRIPTION:
!> @brief reads grain_radii
!! from datafile 0D_grain_sizes.in
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine get_grain_radii()
use global_variables
implicit none
! Locals
character(len=80) :: filename
character(len=80) :: filename_static
integer :: i,j,nb_lines, nb_lines_static
character(len=1000) :: line
character(len=1), parameter :: comment_character = '!' ! character that will indicate that the rest of the line is a comment
integer :: comment_position ! the index of the comment character on the line. if zero, there is none on the current string
integer :: error ! to store the state of a read instruction
logical :: isDefined
!if (is_dust_1D.eq.0 ) then
if (STRUCTURE_TYPE.eq.'0D') then
if (multi_grain.eq.0) then
nb_grains = 1
allocate(grain_radii(nb_grains))
grain_radii(1:nb_grains) = 0.d0
allocate(grain_temp(nb_grains))
grain_temp(1:nb_grains) = 0.d0
allocate(CR_PEAK_GRAIN_TEMP_all(nb_grains))
CR_PEAK_GRAIN_TEMP_all(1:nb_grains) = 0.d0
allocate(actual_dust_temp(nb_grains))
actual_dust_temp(1:nb_grains) = 0.d0
allocate(INDGRAIN(nb_grains))
INDGRAIN(1:nb_grains) = 0
allocate(INDGRAIN_MINUS(nb_grains))
INDGRAIN_MINUS(1:nb_grains) = 0
allocate(sumlaysurfsave(nb_grains))
sumlaysurfsave(1:nb_grains) = 0.d0
allocate(sumlaymantsave(nb_grains))
sumlaymantsave(1:nb_grains) = 0.d0
allocate(EVAPORATION_RATES_H2(nb_grains))
EVAPORATION_RATES_H2(1:nb_grains) = 0.d0
allocate(EVAPORATION_RATES_TEMPO_H2(nb_grains))
EVAPORATION_RATES_TEMPO_H2(1:nb_grains) = 0.d0
allocate(YGRAIN(nb_grains))
YGRAIN(1:nb_grains) = ""
allocate(YGRAIN_MINUS(nb_grains))
YGRAIN_MINUS(1:nb_grains) = ""
allocate(GTODN(nb_grains))
GTODN(1:nb_grains) = 0.d0
allocate(nb_sites_per_grain(nb_grains))
nb_sites_per_grain(1:nb_grains) = 0.d0
grain_radii(:)=grain_radius
CR_PEAK_GRAIN_TEMP_all(:)=cr_peak_grain_temp
grain_temp(:)= initial_dust_temperature
elseif (multi_grain.eq.1) then
filename='0D_grain_sizes.in'
inquire(file=filename, exist=isDefined)
if (isDefined) then
call get_linenumber(filename, nb_lines)
! if (nb_grains.ne.nb_lines) then
! write(Error_unit,'(a)') 'Please check: nb_grains in parameters.in is different than the number of grains in 0D_grains_sizes.in'
! call exit(22)
! endif
nb_grains = nb_lines
allocate(grain_radii(nb_grains))
grain_radii(1:nb_grains) = 0.d0
allocate(grain_temp(nb_grains))
grain_temp(1:nb_grains) = 0.d0
allocate(GTODN_0D_temp(nb_grains))
GTODN_0D_temp(1:nb_grains) = 0.d0
allocate(CR_PEAK_GRAIN_TEMP_all(nb_grains))
CR_PEAK_GRAIN_TEMP_all(1:nb_grains) = 0.d0
allocate(actual_dust_temp(nb_grains))
actual_dust_temp(1:nb_grains) = 0.d0
allocate(INDGRAIN(nb_grains))
INDGRAIN(1:nb_grains) = 0
allocate(INDGRAIN_MINUS(nb_grains))
INDGRAIN_MINUS(1:nb_grains) = 0
allocate(sumlaysurfsave(nb_grains))
sumlaysurfsave(1:nb_grains) = 0.d0
allocate(sumlaymantsave(nb_grains))
sumlaymantsave(1:nb_grains) = 0.d0
allocate(EVAPORATION_RATES_H2(nb_grains))
EVAPORATION_RATES_H2(1:nb_grains) = 0.d0
allocate(EVAPORATION_RATES_TEMPO_H2(nb_grains))
EVAPORATION_RATES_TEMPO_H2(1:nb_grains) = 0.d0
allocate(YGRAIN(nb_grains))
YGRAIN(1:nb_grains) = ""
allocate(YGRAIN_MINUS(nb_grains))
YGRAIN_MINUS(1:nb_grains) = ""
allocate(GTODN(nb_grains))
GTODN(1:nb_grains) = 0.d0
allocate(nb_sites_per_grain(nb_grains))
nb_sites_per_grain(1:nb_grains) = 0.d0
open(10, file=filename, status='old')
i = 1
do
read(10, '(a)', iostat=error) line
if (error /= 0) exit
! We get only what is on the left of an eventual comment parameter
comment_position = index(line, comment_character)
! if there are comments on the current line, we get rid of them
if (comment_position.ne.0) then
line = line(1:comment_position - 1)
end if
if (line.ne.'') then
read(line,*) grain_radii(i), GTODN_0D_temp(i), grain_temp(i), CR_PEAK_GRAIN_TEMP_all(i)
i = i + 1
endif
enddo
else
write(Error_unit,*) 'Error: The file ', trim(filename),' does not exist.'
call exit
endif
close(10)
endif
endif
! do i=1,nb_grains
! write(*, *) i, grain_radii(i),grain_temp(i)
! enddo
! pause
!if (is_dust_1D.eq.1 ) then
if ((STRUCTURE_TYPE.eq.'1D_no_diff').or.(STRUCTURE_TYPE.eq.'1D_diff')) then
if (multi_grain == 0) then
nb_grains = 1
allocate(grain_radii(nb_grains))
grain_radii(1:nb_grains) = 0.d0
allocate(grain_temp(nb_grains))
grain_temp(1:nb_grains) = 0.d0
allocate(CR_PEAK_GRAIN_TEMP_all(nb_grains))
CR_PEAK_GRAIN_TEMP_all(1:nb_grains) = 0.d0
allocate(actual_dust_temp(nb_grains))
actual_dust_temp(1:nb_grains) = 0.d0
allocate(INDGRAIN(nb_grains))
INDGRAIN(1:nb_grains) = 0
allocate(INDGRAIN_MINUS(nb_grains))
INDGRAIN_MINUS(1:nb_grains) = 0
allocate(sumlaysurfsave(nb_grains))
sumlaysurfsave(1:nb_grains) = 0.d0
allocate(sumlaymantsave(nb_grains))
sumlaymantsave(1:nb_grains) = 0.d0
allocate(EVAPORATION_RATES_H2(nb_grains))
EVAPORATION_RATES_H2(1:nb_grains) = 0.d0
allocate(EVAPORATION_RATES_TEMPO_H2(nb_grains))
EVAPORATION_RATES_TEMPO_H2(1:nb_grains) = 0.d0
allocate(YGRAIN(nb_grains))
YGRAIN(1:nb_grains) = ""
allocate(YGRAIN_MINUS(nb_grains))
YGRAIN_MINUS(1:nb_grains) = ""
allocate(GTODN(nb_grains))
GTODN(1:nb_grains) = 0.d0
allocate(nb_sites_per_grain(nb_grains))
nb_sites_per_grain(1:nb_grains) = 0.d0
! we do not read 1D_grain_sizes.in or 0D_grain_sizes.in, values are read from 1D_static.dat files
grain_radii(:)=grain_radius !assigning value from parameter.in file, just to be sure that variable has some value
CR_PEAK_GRAIN_TEMP_all(:)=cr_peak_grain_temp !assigning value from parameter.in file
grain_temp(:)= initial_dust_temperature !assigning value from parameter.in file
elseif (multi_grain == 1) then
filename='1D_grain_sizes.in'
filename_static='1D_static.dat'
inquire(file=filename, exist=isDefined)
if (isDefined) then
nb_grains = get_nb_columns(filename)/4.d0 !4 is the number of parameters in the file.
call get_linenumber(filename, nb_lines)
call get_linenumber(filename_static, nb_lines_static)
if (nb_lines.ne.nb_lines_static) then
write(Error_unit,'(a)') 'Please check: number of spatial points in 1D_static.dat different than that in 1D_grain_sizes.in'
call exit(22)
endif
allocate(grain_radii(nb_grains))
grain_radii(1:nb_grains) = 0.d0
allocate(grain_radii_1D(nb_grains,spatial_resolution))
grain_radii_1D(1:nb_grains,1:spatial_resolution) = 0.d0
allocate(CR_PEAK_GRAIN_TEMP_all_1D(nb_grains,spatial_resolution))
CR_PEAK_GRAIN_TEMP_all_1D(1:nb_grains,1:spatial_resolution) = 0.d0
allocate(grain_temp_1D(nb_grains,spatial_resolution))
grain_temp_1D(1:nb_grains,1:spatial_resolution) = 0.d0
allocate(GTODN_1D_temp(nb_grains,spatial_resolution))
GTODN_1D_temp(1:nb_grains,1:spatial_resolution) = 0.d0
allocate(grain_temp(nb_grains))
grain_temp(1:nb_grains) = 0.d0
allocate(CR_PEAK_GRAIN_TEMP_all(nb_grains))
CR_PEAK_GRAIN_TEMP_all(1:nb_grains) = 0.d0
allocate(actual_dust_temp(nb_grains))
actual_dust_temp(1:nb_grains) = 0.d0
allocate(INDGRAIN(nb_grains))
INDGRAIN(1:nb_grains) = 0
allocate(INDGRAIN_MINUS(nb_grains))
INDGRAIN_MINUS(1:nb_grains) = 0
allocate(sumlaysurfsave(nb_grains))
sumlaysurfsave(1:nb_grains) = 0.d0
allocate(sumlaymantsave(nb_grains))
sumlaymantsave(1:nb_grains) = 0.d0
allocate(EVAPORATION_RATES_H2(nb_grains))
EVAPORATION_RATES_H2(1:nb_grains) = 0.d0
allocate(EVAPORATION_RATES_TEMPO_H2(nb_grains))
EVAPORATION_RATES_TEMPO_H2(1:nb_grains) = 0.d0
allocate(YGRAIN(nb_grains))
YGRAIN(1:nb_grains) = ""
allocate(YGRAIN_MINUS(nb_grains))
YGRAIN_MINUS(1:nb_grains) = ""
allocate(GTODN(nb_grains))
GTODN(1:nb_grains) = 0.d0
allocate(nb_sites_per_grain(nb_grains))
nb_sites_per_grain(1:nb_grains) = 0.d0
open(10, file=filename, status='old')
i = 1
do
read(10, '(a)', iostat=error) line
if (error /= 0) exit
! We get only what is on the left of an eventual comment parameter
comment_position = index(line, comment_character)
! if there are comments on the current line, we get rid of them
if (comment_position.ne.0) then
line = line(1:comment_position - 1)
end if
if (line.ne.'') then
read(line,*) (grain_radii_1D(j,i),j=1,nb_grains),(GTODN_1D_temp(j,i),j=1,nb_grains),&
(grain_temp_1D(j,i),j=1,nb_grains),(CR_PEAK_GRAIN_TEMP_all_1D(j,i),j=1,nb_grains)
! write(*,'(10ES14.5)') (grain_radii_1D(j,i),j=1,nb_grains)
! write(*,'(40ES14.5)') (grain_radii_1D(j,i),GTODN_1D_temp(j,i),grain_temp_1D(j,i),CR_PEAK_GRAIN_TEMP_all_1D(j,i),j=1,nb_grains)
! pause
i = i + 1
endif
enddo
grain_radii(1:nb_grains)=grain_radii_1D(1:nb_grains,1)
grain_temp(:)=grain_temp_1D(:,1)
CR_PEAK_GRAIN_TEMP_all(:)=CR_PEAK_GRAIN_TEMP_all_1D(:,1)
! write(*,*)'----',i,(grain_radii_1D(j,i),j=1,nb_grains)
! write(*,*)grain_radii
! write(*,*)grain_radii_1D(:,1)
! pause
else
write(Error_unit,*) 'Error: The file ', trim(filename),' does not exist.'
call exit
endif
close(10)
endif
endif
return
end subroutine get_grain_radii
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author
!> Wasim Iqbal
!
!> @date 2017
!
! DESCRIPTION:
!> @brief assigning values to character variable YGRAIN and YGRAIN_MINUS
!!
!!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine get_YGRAIN()
use global_variables
implicit none
integer :: i
character(2) :: i_c !character variable to convert integer value of j to character j
YGRAIN = ""
YGRAIN_MINUS = ""
do i=1,nb_grains
write(i_c,'(I2.2)')i
YGRAIN(i) = "GRAIN"//trim(i_c)
YGRAIN_MINUS(i)= "GRAIN"//trim(i_c)//"-"
enddo
! write(*,*)(YGRAIN(I),I=1,nb_grains)
! write(*,*)(YGRAIN_MINUS(I),I=1,nb_grains)
end subroutine get_YGRAIN
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author
!> Christophe Cossou
!
!> @date 2014
!
! DESCRIPTION:
!> @brief Read name and mass of all 'basic' elements (basic brick for molecules
!! such as H, He and so on).
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine read_element_in()
! Writes 1D outputs
use global_variables
implicit none
! Locals
character(len=80), parameter :: filename='element.in'
integer :: i
character(len=80) :: line
character(len=1), parameter :: comment_character = '!' ! character that will indicate that the rest of the line is a comment
integer :: comment_position ! the index of the comment character on the line. if zero, there is none on the current string
integer :: error ! to store the state of a read instruction
logical :: isDefined
character(len=80) :: filename_gas = 'gas_species.in'
character(len=80) :: filename_grain = 'grain_species.in'
integer :: nb_columns_gas
integer :: nb_columns_grain
inquire(file=filename, exist=isDefined)
call get_linenumber(filename, NB_PRIME_ELEMENTS)
! We get the number of prime elements
nb_columns_gas = get_nb_columns(filename_gas)
if ((nb_columns_gas - 2).ne.NB_PRIME_ELEMENTS) then
write (Error_unit,'(a,i0,a,a,a,i0,a)') 'The number of prime elements is different in "element.in" (', NB_PRIME_ELEMENTS, &
') and "', trim(filename_gas), '" (', nb_columns_gas-2, ') .'
call exit(6)
endif
nb_columns_grain = get_nb_columns(filename_grain)
if ((nb_columns_grain - 2).ne.NB_PRIME_ELEMENTS) then
write (Error_unit,'(a,i0,a,a,a,i0,a)') 'The number of prime elements is different in "element.in" (', NB_PRIME_ELEMENTS, &
') and "', trim(filename_grain), '" (', nb_columns_grain-2, ') .'
call exit(6)
endif
! We allocate global variables
allocate(element_name(NB_PRIME_ELEMENTS))
allocate(elemental_mass(NB_PRIME_ELEMENTS))
element_name(1:NB_PRIME_ELEMENTS) = ''
elemental_mass(1:NB_PRIME_ELEMENTS) = 0.d0
if (isDefined) then
open(10, file=filename, status='old')
i = 1
do
read(10, '(a)', iostat=error) line
if (error /= 0) exit
! We get only what is on the left of an eventual comment parameter
comment_position = index(line, comment_character)
! if there are comments on the current line, we get rid of them
if (comment_position.ne.0) then
line = line(1:comment_position - 1)
end if
if (line.ne.'') then
read(line, '(a, f8.3)') element_name(i), elemental_mass(i)
i = i + 1
endif
enddo
close(10)
endif
! Other operations are done once species from gas and grain are read, because we need the indexes of all prime element in those arrays
return
end subroutine read_element_in
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
!> @author
!> Christophe Cossou
!
!> @date 2014
!
! DESCRIPTION:
!> @brief Read simulation parameters from the file parameters.in
!
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine read_parameters_in()
use global_variables
implicit none
character(len=80) :: filename = 'parameters.in' !< name of the file in which parameters are stored
character(len=80) :: line
character(len=1), parameter :: comment_character = '!' !< character that will indicate that the rest of the line is a comment
integer :: comment_position !< the index of the comment character on the line. if zero, there is none on the current string
integer :: error !< to store the state of a read instruction
logical :: isParameter, isDefined
character(len=80) :: identificator, value
!------------------------------------------------------------------------------
inquire(file=filename, exist=isDefined)
if (isDefined) then
open(10, file=filename, status='old')
do
read(10, '(a)', iostat=error) line
if (error /= 0) exit
! We get only what is on the left of an eventual comment parameter
comment_position = index(line, comment_character)
! if there are comments on the current line, we get rid of them
if (comment_position.ne.0) then
line = line(1:comment_position - 1)
end if
call get_parameter_value(line, isParameter, identificator, value)
if (isParameter) then
select case(identificator)
! Solver
case('relative_tolerance', 'RTOL') ! The old name is kept for compatibility reasons
read(value, '(e12.6)') RELATIVE_TOLERANCE
!Switches
case('is_3_phase')
read(value, '(i2)') is_3_phase
!case('is_dust_1D')
! read(value, '(i2)') is_dust_1D
case('photo_disk')
read(value, '(i2)') photo_disk
!case('nb_grains')
! read(value, '(i4)') nb_grains
case('multi_grain')
read(value, '(i2)') multi_grain
case('is_grain_reactions', 'IDUST') ! The old name is kept for compatibility reasons
read(value, '(i2)') IS_GRAIN_REACTIONS
case('is_h2_adhoc_form')
read(value, '(i2)') IS_H2_ADHOC_FORM
case('is_h2_formation_rate')
read(value, '(i2)') is_h2_formation_rate
case('height_h2formation')
read(value, '(i2)') height_h2formation
case('preliminary_test')
read(value, '(i2)') IS_TEST
case('is_absorption_h2')
read(value, '(i2)') is_absorption_h2
case('is_absorption_co')
read(value, '(i2)') is_absorption_co
case('is_absorption_n2')
read(value, '(i2)') is_absorption_n2
case('is_photodesorb')
read(value, '(i2)') is_photodesorb
case('is_crid')
read(value, '(i2)') is_crid
case('is_er_cir')
read(value, '(i2)') is_er_cir
case('grain_tunneling_diffusion', 'IGRQM') ! The old name is kept for compatibility reasons
read(value, '(i2)') GRAIN_TUNNELING_DIFFUSION
case('modify_rate_flag', 'IMODH') ! The old name is kept for compatibility reasons
read(value, '(i2)') MODIFY_RATE_FLAG