-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_model.jl
4567 lines (3729 loc) · 185 KB
/
01_model.jl
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
### A Pluto.jl notebook ###
# v0.20.3
using Markdown
using InteractiveUtils
# ╔═╡ fed88caa-1520-41f7-adb3-785e5c9529c6
using ChaosTools, DataFrames, DataFramesMeta, DelimitedFiles, DifferentialEquations, Interpolations, LinearAlgebra, PlutoUI, QuadGK, SpecialFunctions, Symbolics, TikzPictures, Trapz, Unitful, UnitfulAstro
# ╔═╡ 734b3b08-061e-4f93-8574-468d824815da
# ╠═╡ skip_as_script = true
#=╠═╡
TableOfContents(title="🌌 SF model", depth=4)
╠═╡ =#
# ╔═╡ 53ad27ee-c5be-4d29-9ed5-21b6b64de42b
# ╠═╡ skip_as_script = true
#=╠═╡
md"# Star formation model"
╠═╡ =#
# ╔═╡ a8f2765b-444f-4f3a-8a19-fbcfa6e79d2c
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
## Motivation
The star formation rate (SFR) is a key characteristic of galaxies. In the context of the standard cosmological model ($\Lambda$CDM), the SFR is given by a combination of processes that take place over the course of a galaxy's lifetime, such as gas cooling, star formation, chemical enrichment, and feedback from supernovae and galactic nuclei. These processes are influenced by factors like mergers, interactions, and mass accretion, which affect the amount and properties of the star forming gas. The density of a gas cloud is believed to be the most important factor in determining its star formation rate, although the details of this process are not yet fully understood. Observationally, the total gas density is found to be correlated to the star formation rate ([Kennicutt1998](https://doi.org/10.1086/305588)), and this correlation is even stronger with molecular gas ([Wong2002](https://doi.org/10.1086/339287), [Bigiel2008](https://doi.org/10.1088/0004-6256/136/6/2846)). The underlying reason is the intrinsic relation between the molecular gas mass and the SFR, which can be found at resolved scales ([Baker2021](https://doi.org/10.1093/mnras/stab3672)) and at integrated (i.e. galaxy-wide) scales across redshifts ([Baker2022](https://doi.org/10.1093/mnras/stac3413)).
Because the formation of dark matter halos and galaxies is highly non-linear, numerical simulations have become the preferred tool to investigate how galaxies form and evolve from early times up to the present. This type of simulation naturally includes mergers/interactions and continuous gas accretion. However, there are still significant uncertainties in the modeling of the baryonic component, since the physical processes that affect baryons – such as star formation, feedback, and chemical enrichment – take place at scales that are too small to be resolved directly. As a result, these processes are introduced using sub-grid physics involving several adjustable parameters that are not always independent of one another or constrained by observations. This can lead to inconsistencies in the predictions of different models ([Scannapieco2012](https://doi.org/10.1111/j.1365-2966.2012.20993.x), [Zhu2016](https://doi.org/10.3847/0004-637X/831/1/52), [Naab2017](https://doi.org/10.1146/annurev-astro-081913-040019)).
Because of its importance in galaxy formation, it is critical for simulations to accurately describe the star formation process at the scales that can be resolved and the associated feedback effects.
"""
╠═╡ =#
# ╔═╡ c23a574d-4150-47a8-bcaf-45ae5a8c7c66
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
## Previous work
As the precision of $\mathrm{H_2}$ measurements increases, so too must the sophistication of simulations that model its formation and evolution. Many simulations use an equilibrium model to define the $\mathrm{H_2}$ content, which assumes that the chemistry in each volume element is in a state of equilibrium given only by local variables ([Krumholz2008](https://doi.org/10.1086/592490), [McKee2010](https://doi.org/10.1088/0004-637X/709/1/308), [Krumholz2011](https://doi.org/10.1088/0004-637X/729/1/36), and [Krumholz2013](https://doi.org/10.1093/mnras/stt1780)). However, this assumption is not always valid; as the formation and destruction of $\mathrm{H_2}$ can be influenced by a variety of factors, including temperature, density, and the presence of ultraviolet (UV) radiation.
In [Gnedin2009](https://doi.org/10.1088/0004-637X/697/1/55) it is described, for the first time, a non-equilibrium chemical network for molecular hydrogen. This network uses rate equations to track the formation and destruction of $\mathrm{H_2}$ in each volume element, considering a variety of factors that can influence its abundance. In the last decade, several non-equilibrium models have been developed and implemented in hydrodynamical simulations. In general, they use radiative transfer to model the radiation field, which, in conjunction with a chemical network (a set of ODEs), evolves the abundance of molecular hydrogen and other species of hydrogen and helium. A summary table of previous work can be seen below
| Reference | Code |
|:-------------:|:----:|
| [Gnedin2009](https://doi.org/10.1088/0004-637X/697/1/55) and [Gnedin2011](https://doi.org/10.1088/0004-637X/728/2/88) | $\texttt{ART}$ ([Kravtsov1997](https://doi.org/10.1086/313015)) |
| [Christensen2012](https://doi.org/10.1111/j.1365-2966.2012.21628.x) | $\texttt{GASOLINE}$ ([Wadsley2004](https://doi.org/10.1016/j.newast.2003.08.004)) |
| [Tomassetti2014](https://doi.org/10.1093/mnras/stu2273) | $\texttt{RAMSES}$ ([Teyssier2001](https://doi.org/10.1051/0004-6361:20011817)) |
| [Baczynski2015](https://doi.org/10.1093/mnras/stv1906) | $\texttt{FLASH4}$ ([Fryxell2000](https://doi.org/10.1086/317361)) |
| [Richings2016](https://doi.org/10.1093/mnras/stw327) | $\texttt{GADGET3}$ ([Springel2005](https://doi.org/10.1111/j.1365-2966.2005.09655.x)) |
| [Hu2016](https://doi.org/10.1093/mnras/stw544) | $\texttt{GADGET3}$ ([Springel2005](https://doi.org/10.1111/j.1365-2966.2005.09655.x)) |
| [Katz2017](https://doi.org/10.1093/mnras/stx608) | $\texttt{RAMSES-RT}$ ([Rosdahl2013](https://doi.org/10.1093/mnras/stt1722)) |
| [Pallottini2017](https://doi.org/10.1093/mnras/stx608) | $\texttt{RAMSES}$ ([Teyssier2001](https://doi.org/10.1051/0004-6361:20011817)) |
| [Lupi2017](https://doi.org/10.1093/mnras/stx2874) | $\texttt{GASOLINE2}$ ([Wadsley2017](https://doi.org/10.1093/mnras/stx1643)) |
| [Capelo2018](https://doi.org/10.1093/mnras/stx3355) | $\texttt{GIZMO}$ ([Hopkins2015](https://doi.org/10.1093/mnras/stv195)) |
| [Nickerson2018](https://doi.org/10.1093/mnras/sty1556) and [Nickerson2019](https://doi.org/10.1093/mnras/stz048) | $\texttt{RAMSES-RT}$ ([Rosdahl2013](https://doi.org/10.1093/mnras/stt1722)) |
| [Sillero2021](https://doi.org/10.1093/mnras/stab1015) | $\texttt{GADGET3}$ ([Springel2005](https://doi.org/10.1111/j.1365-2966.2005.09655.x)) |
As an alternative to the computationally expensive radiative transfer process, semi-analytical models (SAMs) have been developed for the multiphase structure of the interstellar medium (MP ISM). Broadly, there are two ways to model the MP ISM, one considers the physical properties of the gas (hot and cold phases), and the other its chemical composition (hydrogen phases).
The former was pioneer by [Field1969](https://doi.org/10.1086/180324) (see [Cowie1977](https://doi.org/10.1086/154911), [McKee1977a](https://doi.org/10.1086/155350), and for a review [Cox2005](https://doi.org/10.1146/annurev.astro.43.072103.150615)), within the context of pure SAMs. The model developed by [McKee1977b](https://doi.org/10.1086/155667) was first incorporated into numerical simulation of galaxy formation by [Yepes1997](https://doi.org/10.1093/mnras/284.1.235) (Eulerian simulations) and [Hultman1999](https://ui.adsabs.harvard.edu/abs/1999A%26A...347..769H) (Lagrangian simulations). These works were later extended by [Springel2003](https://doi.org/10.1046/j.1365-8711.2003.06206.x), adding galactic winds driven by star formation as feedback.
[Monaco2004](https://doi.org/10.1111/j.1365-2966.2004.07916.x) developed a SAM in a similar vein to [Springel2003](https://doi.org/10.1046/j.1365-8711.2003.06206.x), providing the theoretical foundation for MUPPI (MUlti-Phase Particle Integrator) ([Murante2010](https://doi.org/10.1111/j.1365-2966.2010.16567.x)), a sub-resolution MP ISM model that adds stellar feedback to $\texttt{GADGET2}$ ([Springel2005](https://doi.org/10.1111/j.1365-2966.2005.09655.x)). MUPPI separates a gas particle in a hot and cold phase if a set of conditions for its density and temperature are met. It then evolves those components, plus a stellar phase and an energy term (energy of the hot gas), using a set of four ODEs.
Based on [Ferrini1992](https://doi.org/10.1086/171066) and later work, [Mollá2015](https://doi.org/10.1111/j.1365-2966.2005.08782.x) developed a SAM to follow the metallicity in galaxies. These chemical evolution models (CEMs) were subsequently improved and extended in [Mollá2015](https://doi.org/10.1093/mnras/stv1102), [Mollá2016](https://doi.org/10.1093/mnras/stw1723), [Mollá2017](https://doi.org/10.1093/mnras/stx419) and [Millán-Irigoyen2020](https://doi.org/10.1093/mnras/staa635). The latter tracks five components: the molecular, atomic, and ionized phases of hydrogen, dust, and the stars.
We will use a sub-resolution SAM, following closely the one developed by [Millán-Irigoyen2020](https://doi.org/10.1093/mnras/staa635) but implemented within the hydrodynamical code $\texttt{AREPO}$ ([Springel2010](https://doi.org/10.1111/j.1365-2966.2009.15715.x)), like the way MUPPI is integrated with $\texttt{GADGET3}$.
"""
╠═╡ =#
# ╔═╡ 417aad38-6928-4b13-9286-3f11efcffb99
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
## Arepo
We use the N-body, magnetohydrodynamics (MHD) code $\texttt{AREPO}$ ([Springel2010](https://doi.org/10.1111/j.1365-2966.2009.15715.x)) to perform the simulations, which we briefly describe here.
The code $\texttt{AREPO}$ is a moving-mesh code that tracks collisionless dynamics in a cosmological setting. Gravitational forces are computed using a conventional TreePM method ([Springel2005](https://doi.org/10.1111/j.1365-2966.2005.09655.x)), which employs a fast Fourier Transform technique for long-range forces and a hierarchical oct-tree algorithm ([Barnes1986](https://doi.org/10.1038/324446a0)) for short-range forces, in conjunction with adaptive time-stepping.
The code $\texttt{AREPO}$ employs a dynamic unstructured mesh, constructed from a Voronoi tessellation of a set of mesh-generating points, to track the MHD. This allows for a finite-volume discretization of the MHD equations. The MHD equations are solved using a second-order Runge–Kutta integration scheme with high-accuracy least-squares spatial gradient estimators of primitive variables ([Pakmor2015](https://doi.org/10.1093/mnras/stv2380)), which enhance the estimators in the original version of $\texttt{AREPO}$.
A distinctive feature of $\texttt{AREPO}$ is the ability to transform the mesh at any time-step through a mesh reconstruction, a capability not found in standard grid-based methods. The mesh construction ensures that each cell contains a specific target mass (within a certain tolerance), meaning that areas of high density are resolved with more cells than areas of low density. Additionally, the mesh generating points can move with the fluid flow, so each cell of the newly constructed mesh moves approximately with the fluid. This allows $\texttt{AREPO}$ to overcome the Galilean non-invariance problem that standard Eulerian mesh codes have and significantly reduce the advection errors that appear in complex supersonic flows. The quasi-Lagrangian nature of the method makes it comparable to other Lagrangian methods such as SPH, although it eliminates several limitations of the SPH method, such as the absence of artificial viscosity, and provides higher accuracy in the hydrodynamics of underdense regions.
"""
╠═╡ =#
# ╔═╡ b842e98e-34e2-40f2-84b6-c180815c2df3
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
## Phases and notation
We will model the interstellar medium as a multi-phase structure made up of four components. Three are the different states of hydrogen: ionized gas with a temperature of $\sim \! 10^4 \, \mathrm{K}$, atomic gas with a temperature of $\sim \! 100 \, \mathrm{K}$, and molecular gas with a temperature of $\sim \! 10 \, \mathrm{K}$. The final component is the stars.
For every reaction that transfers mass between the phases, we will only use the dominant channel. So, even though the gas is mostly made up of hydrogen and helium, only the hydrogen reactions are incorporated into the model. The processes involved are the photoionization of atoms, the recombination of electrons with ions, the conversion of atomic hydrogen into molecular hydrogen, and the destruction of the latter through photodissociation caused by UV light. In addition, we consider the formation of ionized gas by supernovas and the influence of the molecular gas on the SFR.
We characterized each phase by its mass fraction with respect to the total mass of the cell,
|||
|:-------------:|:--------------------:|
| Ionized gas | $f_i(t) := M_i / M_\mathrm{cell}$ |
| Atomic gas | $f_a(t) := M_a / M_\mathrm{cell}$ |
| Molecular gas | $f_m(t) := M_m / M_\mathrm{cell}$ |
| Stars | $f_s(t) := M_s / M_\mathrm{cell}$ |
where $M_i$, $M_a$, $M_m$, $M_s$ are the corresponding masses and
$\begin{equation}
M_\mathrm{cell} := M_i(t) + M_a(t) + M_m(t) + M_s(t) \, ,
\end{equation}$
is the total cell mass.
Now, we will compute the relation between the number density of the $j$ component ($n_j$) and the dimensionless fractions defined above ($f_j := M_j / M_\mathrm{cell}$).
$\begin{equation}
n_j := \frac{N_j}{V_j} = \frac{M_j}{m_j} \, \frac{1}{V_j} = \frac{M_j}{M_\mathrm{cell}} \, \frac{M_\mathrm{cell}}{m_j \, V_j} = f_j \, \frac{M_\mathrm{cell}}{m_j \, x_j \, V_\mathrm{cell}} = f_j \, \frac{\rho_\mathrm{cell}}{m_j \, x_j} \, ,
\end{equation}$
where the quantities are
|||
|:--------:|:----------------------------------------------------------:|
| $V_\mathrm{cell}$ | Volume of the cell |
| $M_\mathrm{cell}$ | Total mass of the cell |
| $\rho_\mathrm{cell}$ | Mass density of the cell |
| $N_j$ | Number of elements (e.g. atoms) of the $j$ component |
| $V_j$ | Total volume of the $j$ component |
| $M_j$ | Total mass of the $j$ component |
| $m_j$ | Mass of a single element (e.g. atoms) of the $j$ component |
| $f_j$ | $(:= M_j / M_\mathrm{cell})$ Mass fraction of the $j$ component |
| $x_j$ | $(:= V_j / V_\mathrm{cell})$ Volume fraction of the $j$ component |
In the context of our model, $V_\mathrm{cell}$, $\rho_\mathrm{cell}$, $M_\mathrm{cell}$, $m_j$, $V_j$, and $x_j$ are constants.
In the same way, we can write a relation for the mass density of the $j$ component,
$\begin{equation}
\rho_j := \frac{M_j}{V_j} = \frac{M_j}{M_\mathrm{cell}} \, \frac{M_\mathrm{cell}}{V_j} = f_j \, \frac{M_\mathrm{cell}}{x_j \, V_\mathrm{cell}} = f_j \, \frac{\rho_\mathrm{cell}}{x_j} \, ,
\end{equation}$
So, using these relations we can write any differential equation for the quantities $M_j$, $\rho_j$, and $n_j$ as an equation for $f_j$.
In our model, we have done only two hypotheses until now. First, that the ISM is only made up of the four components already mentioned, and second, that $V_\mathrm{cell}$, $\rho_\mathrm{cell}$, $M_\mathrm{cell}$, $m_j$, $V_j$, and $x_j$ are constants.
For simplicity we will adopt $x_i = x_a = x_m = 1.0$, which is like assuming that the three hydrogen phases occupy the whole cell.
"""
╠═╡ =#
# ╔═╡ 99d0fdc9-e368-462c-a357-86f07624a52e
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
## Physical relationships
"""
╠═╡ =#
# ╔═╡ 6d6cbebb-bb3b-437d-9835-0a79f36857f2
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
### Physical processes by name
"""
╠═╡ =#
# ╔═╡ 71b94af7-76ee-4228-987c-2f22e0951552
# ╠═╡ skip_as_script = true
#=╠═╡
TikzPictures.TikzPicture(
L"""
\node[box, white] (stars) {Stars};
\node[box, white, text width=2em, above=2.5cm of stars] (atom) {HI};
\node[box, white, text width=2em, right=2cm of atom] (molecule) {\ch{H2}};
\node[box, white, text width=2em, left=2cm of atom] (ion) {HII};
\draw[line, white, ->]
(ion) edge [bend left, "\textcolor{d_pink}{recombination}"] (atom)
(atom) edge [bend left, "\textcolor{d_orange}{condensation}"] (molecule)
(molecule) edge [bend left,"\textcolor{d_green}{dissociation}"] (atom)
(atom) edge [bend left,"\textcolor{d_blue}{ionization}"] (ion)
(stars) edge [bend left, "\textcolor{d_yellow}{supernova}"] (ion)
(molecule) edge [bend left, "\textcolor{red}{star formation}"] (stars);
""",
width="75em",
preamble = """
\\usepackage{chemformula}
\\definecolor{d_pink}{HTML}{C721DD}
\\definecolor{d_orange}{HTML}{D14A00}
\\definecolor{d_green}{HTML}{008C00}
\\definecolor{d_blue}{HTML}{007FB1}
\\definecolor{d_yellow}{HTML}{D1AC00}
\\usetikzlibrary{shapes.misc, arrows, positioning, quotes, fit}
\\tikzset{
>=stealth',
box/.style={
rectangle,
rounded corners,
draw=black,
thick,
text width=4em,
minimum height=2em,
text centered,
},
line/.style = {
thick,
},
every edge quotes/.append style = {
font=\\small,
align=center,
auto,
},
myrect/.style={
rectangle,
draw,
inner sep=0pt,
fit=\\#1,
thick,
rounded corners,
},
}
""",
)
╠═╡ =#
# ╔═╡ 22c37732-1cf7-4d80-a250-9fd5e4a2f88c
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
### Physical processes as mathematical expressions
"""
╠═╡ =#
# ╔═╡ 2acad39a-23b7-4004-bf0e-59e73b914f01
# ╠═╡ skip_as_script = true
#=╠═╡
TikzPictures.TikzPicture(
L"""
\node[box, white] (stars) at (180:2cm) {Stars};
\node[box, white, text width=2em] (atom) at (0:2cm) {HI};
\node[box, white, text width=2em] (molecule) at (270:2cm) {\ch{H2}};
\node[box, white, text width=2em] (ion) at (90:2cm) {HII};
\draw[line, white, ->]
(ion) edge [bend left, "$\textcolor{d_pink}{\frac{f_i(t)}{\tau_\mathrm{rec}(t)}} - \textcolor{d_blue}{\eta_\text{ion} \, \psi(t)}$"] (atom)
(atom) edge [bend left, "$\textcolor{d_orange}{\frac{f_a(t)}{\tau_\mathrm{cond}(t)}} - \textcolor{d_green}{\eta_\text{diss} \, \psi(t)}$"] (molecule)
(stars) edge [bend left, "$\textcolor{d_yellow}{R \, \psi(t)}$"] (ion)
(molecule) edge [bend left, "$\textcolor{red}{\psi(t)}$"] (stars);
""",
width="75em",
preamble = """
\\usepackage{chemformula}
\\definecolor{d_pink}{HTML}{C721DD}
\\definecolor{d_orange}{HTML}{D14A00}
\\definecolor{d_green}{HTML}{008C00}
\\definecolor{d_blue}{HTML}{007FB1}
\\definecolor{d_yellow}{HTML}{D1AC00}
\\usetikzlibrary{shapes.misc, arrows, positioning, quotes, fit}
\\tikzset{
>=stealth',
box/.style={
rectangle,
rounded corners,
draw=black,
thick,
text width=4em,
minimum height=2em,
text centered,
},
line/.style = {
thick,
},
every edge quotes/.append style = {
font=\\small,
align=center,
auto,
},
myrect/.style={
rectangle,
draw,
inner sep=0pt,
fit=\\#1,
thick,
rounded corners,
},
}
""",
)
╠═╡ =#
# ╔═╡ 82991902-223e-42bb-80f4-9d6260f8a040
# ╠═╡ skip_as_script = true
#=╠═╡
md"## Equations"
╠═╡ =#
# ╔═╡ c5e21675-f120-4555-84be-d99b35592f2d
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
### Stars
We define $\psi(t)$ as the fractional star formation rate (SFR per unit of cell mass),
$\begin{equation}
\left. \frac{\mathrm{d}}{\mathrm{d}t}f_s(t) \right|_{\text{SFR}} =: \psi(t) \, ,
\end{equation}$
### Ionized gas
The ionized component grows through the ionization of atomic gas and from the remnants of supernova explosions.
The former is produced mainly by the radiation of newborn stars, so it is given by
$\begin{equation}
\left. \frac{\mathrm{d}}{\mathrm{d}t}f_i(t)\right|_{\text{ion.}} = \eta_\text{ion} \, \psi(t) \, ,
\end{equation}$
where $\eta_\text{ion}$ is the ionized mass rate per unit of created stellar mass. All the physics of the ionization process are summarized in this parameter, which is assumed constant during the integration of the differential equations.
The latter, under the instantaneous recycling hypothesis, can be written as
$\begin{equation}
\left. \frac{\mathrm{d}}{\mathrm{d}t}f_i(t)\right|_{\text{recyc.}} = R \, \psi(t) \, ,
\end{equation}$
where $R$ is the mass fraction of a stellar population that is returned to the ISM, where we assumed that all the returned mass is in the form of ionized gas. Ignoring the metal enrichment is a good approximation that does not alter significantly the results. This parameter it is also assumed constant while integrating the differential equations.
### Atomic gas
The atomic component grows through the dissociation of hydrogen molecules and the recombination of the ionized gas with free electrons.
The former, as with the ionized gas, is given by
$\begin{equation}
\left. \frac{\mathrm{d}}{\mathrm{d}t}f_a(t)\right|_{\text{diss.}} = \eta_\text{diss} \, \psi(t) \, ,
\end{equation}$
where $\eta_\text{diss}$ is the disassociated mass rate per unit of created stellar mass, also assumed constant during the ODEs integration.
The latter will depend on the mass of ionized gas and the time scale of recombination ($\tau_\mathrm{rec}$), so it is given by
$\begin{equation}
\left. \frac{\mathrm{d}}{\mathrm{d}t}f_a(t)\right|_{\text{recon.}} = \frac{f_i(t)}{\tau_\mathrm{rec}(t)} \, .
\end{equation}$
### Molecular gas
The molecular component gains mass mainly by the condensation of hydrogen atoms on the surface of dust grains. This process depends on the mass of atomic gas and the characteristic time scale of condensation ($\tau_\mathrm{cond}$). We are putting all the dust physics into this time parameter,
$\begin{equation}
\left. \frac{\mathrm{d}}{\mathrm{d}t}f_m(t)\right|_{\text{cond.}} = \frac{f_a(t)}{\tau_\mathrm{cond}(t)} \, ,
\end{equation}$
"""
╠═╡ =#
# ╔═╡ 8dcc45e1-192a-4007-9d6e-6e4149b563d7
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
From all the above, we can write the system of four ODEs,
"""
╠═╡ =#
# ╔═╡ d12b4a5f-a6ad-4c91-8795-fe8f93f5c93d
# ╠═╡ skip_as_script = true
#=╠═╡
TikzPictures.TikzPicture(
L"""
\node[white] {
${\boldmath
\begin{aligned}
\dv{}{t}f_i(t) &= - \textcolor{d_pink}{\frac{f_i(t)}{\tau_\mathrm{rec}(t)}} + \textcolor{d_blue}{\eta_\text{ion} \, \psi(t)} + \textcolor{d_yellow}{R \, \psi(t)} \, , \\
\dv{}{t}f_a(t) &= \textcolor{d_pink}{\frac{f_i(t)}{\tau_\mathrm{rec}(t)}} - \textcolor{d_blue}{\eta_\text{ion} \, \psi(t)} - \textcolor{d_orange}{\frac{f_a(t)}{\tau_\mathrm{cond}(t)}} + \textcolor{d_green}{\eta_\text{diss} \, \psi(t)} \, , \\
\dv{}{t}f_m(t) &= \textcolor{d_orange}{\frac{f_a(t)}{\tau_\mathrm{cond}(t)}} - \textcolor{d_green}{\eta_\text{diss} \, \psi(t)} - \textcolor{red}{\psi(t)} \, , \\
\dv{}{t}f_s(t) &= \textcolor{red}{\psi(t)} - \textcolor{d_yellow}{R \, \psi(t)} \, ,
\end{aligned}}$
};
""",
width="75em",
preamble = """
\\usepackage{chemformula}
\\usepackage{physics}
\\setlength{\\jot}{10pt}
\\definecolor{d_pink}{HTML}{C721DD}
\\definecolor{d_orange}{HTML}{D14A00}
\\definecolor{d_green}{HTML}{008C00}
\\definecolor{d_blue}{HTML}{007FB1}
\\definecolor{d_yellow}{HTML}{D1AC00}
""",
)
╠═╡ =#
# ╔═╡ c7eee8bb-b03d-4679-a51e-36fc629294e1
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
And we can explicitly check mass conservation,
$\begin{equation}
\frac{\mathrm{d}}{\mathrm{d}t}(f_i + f_a + f_m + f_s) = 0 \, .
\end{equation}$
"""
╠═╡ =#
# ╔═╡ 7112c2fc-0cd6-407f-afaf-56a49e02fa57
# ╠═╡ skip_as_script = true
#=╠═╡
md"## ODE coefficients"
╠═╡ =#
# ╔═╡ 6b135719-c120-4b69-aed3-28647fc601bf
# ╠═╡ skip_as_script = true
#=╠═╡
md"### Stiffness coefficient"
╠═╡ =#
# ╔═╡ f036dffd-8aab-4337-9f1a-a1870da284df
# ╠═╡ skip_as_script = true
#=╠═╡
md"The model, for a typical set of initial conditions, is very stiff (stiffness ratio >> 1)."
╠═╡ =#
# ╔═╡ fd7e6a35-72a0-4133-b43c-95ee73da5fc4
# ╠═╡ skip_as_script = true
#=╠═╡
md"### Lyapunov spectrum"
╠═╡ =#
# ╔═╡ 4d09ff8b-fd43-4b4a-ba9d-030e9d2b6cec
# ╠═╡ skip_as_script = true
#=╠═╡
md"The model, for a typical set of initial conditions, is not chaotic (maximum lyapunov exponent < 0). But, we note that with a higher density the system can turn chaotic (maximum lyapunov exponent > 0)."
╠═╡ =#
# ╔═╡ 700015f6-aac0-40c5-a455-8d98c1227049
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
## Units
We have the freedom to choose three independent units in this model. Time, mass, and length. The choice is reflected in the constants $C_\mathrm{star}$, $C_\mathrm{rec}$, and $C_\mathrm{cond}$.
Following the standard in astronomy and astrophysics, we will use $\mathrm{[T] = Myr}$, $\mathrm{[M] = mp}$ and $\mathrm{[L] = cm}$, where $\mathrm{mp}$ is the proton mass.
"""
╠═╡ =#
# ╔═╡ 207305eb-4496-4518-a5bc-be85173314a5
begin
const t_u = u"Myr"
const m_u = u"mp"
const l_u = u"cm"
end;
# ╔═╡ a6fdec29-3438-4ebc-af81-7a3baf0175ae
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
# Parameters
* $\psi(t)$: Star formation rate.
* $\tau_\mathrm{rec}$: Time scale of atomic gas formation, from ionized gas, generally called recombination time.
* $\tau_\mathrm{cond}$: Time scale of molecular gas formation, from atomic gas, generally called condensation (or cloud formation) time.
* $\eta_\mathrm{diss}$: Rate of molecular gas dissociation by stars per unit of created stellar mass.
* $\eta_\mathrm{ion}$: Rate of atomic gas ionization by stars per unit of created stellar mass.
* $R$: Mass of ionized gas produced per unit of created stellar mass.
"""
╠═╡ =#
# ╔═╡ ee7baf70-c7af-4791-8277-fadc0961e0e7
# ╠═╡ skip_as_script = true
#=╠═╡
md"## Physical processes"
╠═╡ =#
# ╔═╡ 72416f96-8a0a-4c13-97d1-2990e49c4cb0
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
### Star formation
For the formation of stars we will use the notation and definitions commonly used in the field (for a review see [McKee2007](https://doi.org/10.1146/annurev.astro.45.051806.110602), [Krumholz2014](https://doi.org/10.1016/j.physrep.2014.02.001), and [Krumholz2019](https://doi.org/10.1146/annurev-astro-091918-104430)).
In particular, we will follow [Krumholz2005](https://doi.org/10.1086/431734), but taking into account the correlation between molecular hydrogen and star formation ([Bigiel2008](https://doi.org/10.1088/0004-6256/136/6/2846), [Bigiel2010](https://doi.org/10.1088/0004-6256/140/5/1194), [Wong2002](https://doi.org/10.1086/339287), [Robertson2008](https://doi.org/10.1086/587796), [Halle2013](https://doi.org/10.1051/0004-6361/201220952), [Thompson2013](https://doi.org/10.1088/0004-637x/780/2/145)).
So, our model is
$\begin{equation}
\mathrm{SFR} := \frac{\mathrm{d}}{\mathrm{d}t} M_s = \frac{M_m}{\tau_\mathrm{star}}
\end{equation}$
where $M_m$ is the molecular mass and $\tau_\mathrm{star}$ is the characteristic timescale of star formation (defined by this very relation).
Given that we want equations for the dimensionless fraction, we will use
$\begin{equation}
\psi := \frac{\mathrm{SFR}}{M_\mathrm{cell}} = \frac{M_m}{\tau_\mathrm{star}} \, \frac{1}{M_\mathrm{cell}} = \frac{f_m}{\tau_\mathrm{star}} \, .
\end{equation}$
"""
╠═╡ =#
# ╔═╡ 099a7feb-019a-4e37-9332-592c9b1dc0ed
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
Following [Krumholz2005](https://doi.org/10.1086/431734), we write the characteristic timescale of star formation as
$\begin{equation}
\tau_\mathrm{star} = \frac{t_\text{ff}}{\epsilon_\text{ff}} \, ,
\end{equation}$
where $\epsilon_\text{ff}$ is the star formation efficiency (in the literature is often used $\epsilon_\text{ff} \approx 0.01$ [Krumholz2007](https://doi.org/10.1086/509101), [Krumholz2014](https://doi.org/10.1016/j.physrep.2014.02.001)) and $t_\text{ff}$ is the free-fall time, which is the time for a pressure-free spherical cloud to collapse into a point due to its self-gravity.
The free-fall time can be written as
$\begin{equation}
t_\text{ff} = \sqrt{\frac{3\pi}{32 \, G\, \rho_g}} \, ,
\end{equation}$
where $\rho_g$ is the density of the gas cloud.
There is a lot of uncertainty for the parameter $\epsilon_\text{ff}$ ([Lee2016](https://doi.org/10.3847/1538-4357/833/2/229) and [Utomo2018](https://doi.org/10.3847/2041-8213/aacf8f)). We will use $\epsilon_\text{ff} = 1.0$ because we already consider the low efficiency of star formation when only molecular hydrogen is used to form stars. We note though, that this parameter has been shown to have little influence on the global properties of simulated galaxies ([Li2018](https://doi.org/10.3847/1538-4357/aac9b8) and [Brown2022](https://doi.org/10.1093/mnras/stac1164)).
With all the previous definitions, we have
$\begin{equation}
\tau_\mathrm{star} = \frac{C_\mathrm{star}}{\sqrt{\rho_g}} \, ,
\end{equation}$
where
$\begin{equation}
C_\mathrm{star} = \sqrt{\frac{3\pi}{32 \, G}} \, .
\end{equation}$
Given that $\rho_g$ is the density of an individual cold gas cloud, which is unresolved within a cell, we will simply use $\rho_g = \rho_\mathrm{cell}$.
"""
╠═╡ =#
# ╔═╡ 0baae21f-71b5-42fd-be33-31de085928d3
begin
const ϵff = 1.0
const C_star = sqrt(3π / 32u"G") / ϵff
const c_star = ustrip(t_u * l_u^-(3/2), C_star / sqrt(m_u))
τ_star(ρ_cell) = c_star / sqrt(ρ_cell)
ψ(fm, ρ_cell) = fm / τ_star(ρ_cell)
end;
# ╔═╡ a7c5650c-9bbc-44a1-8d51-d473864faae7
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
### Recombination
The rate of recombination for hydrogen atoms can be written as ([Osterbrock2006](http://www.worldcat.org/oclc/60611705), [Gnedin2009](https://doi.org/10.1088/0004-637X/697/1/55), [Christensen2012](https://doi.org/10.1111/j.1365-2966.2012.21628.x), and [Millan-Irigoyen2020](https://doi.org/10.1093/mnras/staa635))
$\begin{equation}
\frac{d}{dt} n_a \biggr\rvert_\mathrm{recomb.} = \alpha_H(T) \, n_e \, n_i \, ,
\end{equation}$
where $\alpha_H(T)$ is the recombination coefficient, $n_e$ is the electron number density, and $n_i$ is the ionized hydrogen number density. We note that, by mass balance and within our model, $n_e = n_i$.
Using the conversion factor already mentioned, we can write
$\begin{align}
\frac{d}{dt} f_a \biggr\rvert_\mathrm{recomb.} &= \frac{x_a \, m_p}{\rho_\mathrm{cell}} \, \alpha_H(T) \, n_e \, n_i \\
&= \frac{x_a \, m_p}{\rho_\mathrm{cell}} \, \alpha_H(T) \, f_i \, \frac{\rho_\mathrm{cell}}{x_i \, m_p} \, f_i \, \frac{\rho_\mathrm{cell}}{x_i \, m_p} \\
&= \alpha_H(T) \, f_i^{\,2} \, \frac{\rho_\mathrm{cell}}{m_p} \, \frac{x_a}{x_i^{\,2}} \, .
\end{align}$
We can readily find fits for $\alpha_H(T)$ in the literature ([Seaton1959](https://doi.org/10.1093/mnras/119.2.81), [Black1981](https://doi.org/10.1093/mnras/197.3.553), [Verner1996](https://doi.org/10.1086/192284), and [Osterbrock2006](http://www.worldcat.org/oclc/60611705)). In particular, if we take $T = 10^4 \, \mathrm{K}$ for the ionized phase and use case B recombination assuming an optically thick cloud ([Nebrin2023](https://doi.org/10.3847/2515-5172/acd37a)), we get
$\begin{align}
\alpha_H(10^4 \, \mathrm{K}) = \alpha_H = 2.6 \times 10^{-13} \, \mathrm{cm}^3 \, \mathrm{s}^{-1} \, .
\end{align}$
So, we can write
$\begin{equation}
\frac{d}{dt} f_a \biggr\rvert_\mathrm{recomb.} = \alpha_H \, f_i^{\,2} \, \frac{\rho_\mathrm{cell}}{m_p} \, \frac{x_a}{x_i^{\,2}} = \frac{f_i}{\tau_\mathrm{rec}} \, ,
\end{equation}$
where the time scale $\tau_\mathrm{rec}$ is
$\begin{equation}
\tau_\mathrm{rec} = \frac{m_p \, x_i^{\,2}}{\alpha_H \, f_i \, \rho_\mathrm{cell} \, x_a} = \frac{C_\mathrm{rec}}{f_i \, \rho_\mathrm{cell}} \, ,
\end{equation}$
with the constant
$\begin{equation}
C_\mathrm{rec} = \frac{m_p}{\alpha_H} \, \frac{x_i^{\,2}}{x_a} \, .
\end{equation}$
"""
╠═╡ =#
# ╔═╡ 49d1a7f7-2bf2-4472-94df-6247b9237ddd
begin
const αH = 2.6e-13u"cm^3 * s^-1"
const C_rec = m_u / αH
const c_rec = ustrip(t_u * l_u^-3, C_rec / m_u)
τ_rec(fi, ρ_cell) = c_rec / (fi * ρ_cell)
end;
# ╔═╡ 2d6fcef9-df4b-4eec-be5c-a8865c3a1b76
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
### Condensation
From at least [Hollenbach1971a](https://doi.org/10.1086/150754) and [Hollenbach1971b](https://doi.org/10.1086/150755) we know that the rate of molecular hydrogen formation due to the condensation of atomic gas in the surface of dust grains is
$\begin{equation}
\frac{d}{dt} n_m \biggr\rvert_\mathrm{cond.} = R_d \, n_H \, n_a \, ,
\end{equation}$
where $R_d$ is the formation rate coefficient of $H_2$ on dust grain, $n_H$ is the hydrogen nucleus number density, and $n_a$ is the atomic hydrogen number density. $n_H$ comes from the assumption that the number density of dust grains is proportional to it ([Hollenbach1971b](https://doi.org/10.1086/150755) Section II).
In the literature, $n_H$ is generally taken as $n_H = n_a + 2 \, n_m$, because most studies consider cold gas clouds ($T \sim 100 \, \mathrm{K}$) dominated by molecular and atomic hydrogen gas. In contrast, we consider atomic, molecular, and ionized gas within our gas cell; so, we will use $n_H = n_a + 2\, n_m + n_i$.
We also note that the expression for $\frac{d}{dt} n_m$ is only used in equilibrium equations in most of the early works ([Hollenbach1971a](https://doi.org/10.1086/150754), [Hollenbach1971b](https://doi.org/10.1086/150755), [Jura1974](https://doi.org/10.1086/152975), [Jura1975](https://doi.org/10.1086/153545), [Black1987](https://doi.org/10.1086/165740), [Sternberg1988](https://doi.org/10.1086/166664), and [Goldshmidt1995](https://doi.org/10.1086/175168)), while first appearing in an actual differential equation that does not assume equilibrium in [Draine1996](https://doi.org/10.1086/177689).
Using the conversion factor already mentioned we can write
$\begin{align}
\frac{d}{dt} f_m \biggr\rvert_\mathrm{cond.} &= \frac{2 \, m_p \, x_m}{\rho_\mathrm{cell}} \, R_d \, \left( n_a + 2\, n_m + n_i \right) \, n_a \\
&= \frac{2 \, m_p \, x_m}{\rho_\mathrm{cell}} \, R_d \left( f_a \, \frac{\rho_\mathrm{cell}}{m_p \, x_a} + 2 \, f_m \, \frac{\rho_\mathrm{cell}}{2 \, m_p \, x_m} + f_i \, \frac{\rho_\mathrm{cell}}{m_p \, x_i} \right) \, f_a \, \frac{\rho_\mathrm{cell}}{m_p \, x_a} \\
&= 2 \, R_d \left( \frac{f_a}{x_a} + \frac{f_m}{x_m} + \frac{f_i}{x_i} \right) \, f_a \, \frac{\rho_\mathrm{cell}}{m_p} \, \frac{x_m}{x_a} \\
&= \frac{f_a}{\tau_\mathrm{cond}} \, ,
\end{align}$
where the time scale $\tau_\mathrm{cond}$ is
$\begin{equation}
\tau_\mathrm{cond} := \frac{m_p \, x_a}{2 \, R_d \, \rho_\mathrm{cell} \, x_m \left( \dfrac{f_a}{x_a} + \dfrac{f_m}{x_m} + \dfrac{f_i}{x_i} \right)} \, .
\end{equation}$
A table with several values for $R_d$ is presented below. We note that more than one value for $R_d$ and its dependence on other parameters may be discussed within each reference. In the table, we reflect the fiducial value used by each author
| $R_d \,\, [10^{-17} \, \mathrm{cm^3 \, s^{-1}}]$ | Reference |
|:-----:|:--------------------------------------------------:|
| $1$ | [Hollenbach1971b](https://doi.org/10.1086/150755) |
| $5$ | [Jura1974](https://doi.org/10.1086/152975) |
| $3$ | [Jura1975](https://doi.org/10.1086/153545) |
| $9$ | [Black1987](https://doi.org/10.1086/165740) |
| $3$ | [Goldshmidt1995](https://doi.org/10.1086/175168) |
| $6$ | [Draine1996](https://doi.org/10.1086/177689) |
| $3.5$ | [Wolfire2008](https://doi.org/10.1086/587688) |
Theoretical and experimental work has shown that $R_d \propto T^{1/2}$ ([Black1987](https://doi.org/10.1086/165740)) and $R_d \propto n_\mathrm{dust}$ ([Hollenbach1971b](https://doi.org/10.1086/150755)). Assuming the simplest dust model $n_\mathrm{dust} \propto Z$, we have $R_d \propto T^{1/2} \, Z$ ([Pelupessy2006](https://doi.org/10.1086/504366) and [Wolfire2008](https://doi.org/10.1086/587688)).
Following previous prescriptions ([Pelupessy2006](https://doi.org/10.1086/504366), [Gnedin2009](https://doi.org/10.1088/0004-637X/697/1/55), [Christensen2012](https://doi.org/10.1111/j.1365-2966.2012.21628.x), [Mollá2017](https://doi.org/10.1093/mnras/stx419), [Millan-Irigoyen2020](https://doi.org/10.1093/mnras/staa635)) we will only scale $R_d$ with the metallicity and use $\sim 100\,\mathrm{K}$ for the temperature of the cold neutral gas.
Our reference value for $R_d$ at $Z = Z_\odot$ is ([Wolfire2008](https://doi.org/10.1086/587688))
$\begin{equation}
R_\odot := R_d(Z = Z_\odot) = 3.5 \times 10^{-17} \, \mathrm{cm^3 \, s^{-1}} \, ,
\end{equation}$
so, we have
$\begin{equation}
R_d = Z \, \frac{R_\odot}{Z_\odot} \, .
\end{equation}$
The value of $R_\odot$ within $1 \, \mathrm{dex}$ should not affect significantly the results, but we will use an adjustable global factor (like the clumping factor $C_\rho$ in [Gnedin2009](https://doi.org/10.1088/0004-637X/697/1/55) and [Christensen2012](https://doi.org/10.1111/j.1365-2966.2012.21628.x)) to account for all the uncertainties.
The fact that the final expression for $R_d$ would give $0$ when $Z = 0$ is problematic because $\tau_\mathrm{cond}$ would diverge. The problem originates in the incorrect assumption that the only conversion channel for $\mathrm{HI} \rightarrow \mathrm{H_2}$ is the condensation on the surface of dust grains. To solve this we do the replacement $Z \rightarrow Z + Z_\mathrm{eff}$ with $Z_\mathrm{eff} = 10^{-3} \, Z_\odot$, which eliminates the divergence and takes into account the molecular formation that occurs below $10^{-3} \, Z_\odot$ ([Glover2007](https://doi.org/10.1086/519445)).
So, we finally have
$\begin{align}
\tau_\mathrm{cond} &= \frac{m_p \, x_a \, Z_\odot}{2 \, R_\odot \, C_\rho \, (Z + Z_\mathrm{eff}) \, \rho_\mathrm{cell} \, x_m \left( \dfrac{f_a}{x_a} + \dfrac{f_m}{x_m} + \dfrac{f_i}{x_i} \right)} \\
&= \frac{C_\mathrm{cond}}{(Z + Z_\mathrm{eff}) \, \rho_\mathrm{cell} \left( \dfrac{f_a}{x_a} + \dfrac{f_m}{x_m} + \dfrac{f_i}{x_i} \right)} \, ,
\end{align}$
where
$\begin{equation}
C_\mathrm{cond} = \frac{m_p \, x_a \, Z_\odot}{2 \, R_\odot \, C_\rho \, x_m} \, .
\end{equation}$
For the solar metallicity, we find several values in the literature
| $Z_\odot$ | Reference |
|:--------:|:---------------------------------------------------------------------:|
| $0.0169$ | [Draine1996](https://doi.org/10.1086/177689) |
| $0.0153$ | [Grevesse1998](https://doi.org/10.1023/A:1005161325181) |
| $0.0122$ | [Asplund2006](https://doi.org/10.1553/cia147s76) and [Grevesse2007](https://doi.org/10.1007/s11214-007-9173-7) |
| $0.0134$ | [Asplund2009](https://doi.org/10.1146/annurev.astro.46.060407.145222) |
| $0.0141$ | [Lodders2009](https://doi.org/10.1007/978-3-540-88055-4_34) |
| $0.0127$ | $\texttt{AREPO}$ |
| $0.0196$ | [Steiger2015](https://doi.org/10.3847/0004-637X/816/1/13) |
To keep it consistent with the $\texttt{AREPO}$ codebase, we will use $Z_\odot = 0.0127$, noting that is only $35\%$ off the largest value in the list ([Steiger2015](https://doi.org/10.3847/0004-637X/816/1/13)).
We found that we need a $C_\rho \approx 100$ to form a disk, which is a reasonable value for the clumping factor under certain circumstances ([Micic2012](https://doi.org/10.1111/j.1365-2966.2012.20477.x)).
"""
╠═╡ =#
# ╔═╡ 568d9fe3-6716-4a9a-ba1d-b9e6fd039150
begin
const Rsun = 3.5e-17u"cm^3 * s^-1"
const Zsun = 0.0127
const Zeff = 1e-3 * Zsun
const Cρ = 100.0
const C_cond = (m_u * Zsun) / (2 * Rsun * Cρ)
const c_cond = ustrip(t_u * l_u^-3, C_cond / m_u)
τ_cond(fs, ρ_cell, Z) = c_cond / (ρ_cell * (Z + Zeff) * (1.0 - fs))
end;
# ╔═╡ 43ee281f-1a16-445d-894d-23e0319b1fd0
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
## Photodissociation efficiency
We define the disassociated mass rate per unit of created stellar mass as
$\begin{equation}
\eta_\mathrm{diss} = \frac{\dot{M}_\mathrm{diss}}{\mathrm{SFR}} \, ,
\end{equation}$
and the ionized mass rate per unit of created stellar mass as
$\begin{equation}
\eta_\mathrm{ion} = \frac{\dot{M}_\mathrm{ion}}{\mathrm{SFR}} \, .
\end{equation}$
The mass rates, $\dot{M}_\mathrm{diss}$ and $\dot{M}_\mathrm{ion}$, can be computed from the photon production rate
$\begin{align}
\dot{M}_\mathrm{diss} &= \dot{N}_\mathrm{diss} \, c_\mathrm{diss} \, , \\
\dot{M}_\mathrm{ion} &= \dot{N}_\mathrm{ion} \, c_\mathrm{ion} \, ,
\end{align}$
where $\dot{N}_\mathrm{diss}$ is the number of photodissociating photons produced per unit time (in the Lyman–Werner band, $912\,\mathrm{Å}$ to $1107\,\mathrm{Å}$), $\dot{N}_\mathrm{ion}$ the number of ionizing photons produced per unit time (between $0$ and $912\,Å$), and $c_\mathrm{diss}$ and $c_\mathrm{ion}$ are the unit conversion factors (proton mass into solar mass). The factors $c_\mathrm{diss}$ and $c_\mathrm{ion}$ allow us to consider that the reaction may not be $100\%$ efficient too.
For the ionization reaction, each photon will produce one proton and we assume $100\%$ efficiency.
"""
╠═╡ =#
# ╔═╡ d90371c3-3359-41cb-9bc6-27484beddb3c
const c_ion = ustrip(1.0u"mp" |> u"Msun")
# ╔═╡ 1f59c4ca-37c4-4492-8670-4bfdda78bd65
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
For the molecular dissociation reaction, we will consider the numerical factor given by [Draine1996](https://doi.org/10.1086/177689), where it is shown that dust grains may absorb up to $\sim \! 60$ percent of the photons capable of dissociating hydrogen molecules and a large fraction of the remaining photons excite different rotational and vibrational states, reducing their dissociation probability to $\sim \! 15$ percent. So, we end up with an efficiency factor of $0.4 \times 0.15 = 0.06$.
$c_\mathrm{diss}$ has an extra factor of two because each photon contributes with two protons (from the dissociated molecule) to the atomic gas.
"""
╠═╡ =#
# ╔═╡ 1657d7c2-87af-4079-8cf7-7a1164a95cc8
const c_diss = 0.4 * 0.15 * 2.0 * ustrip(1.0u"mp" |> u"Msun")
# ╔═╡ 4d09ed45-423c-4bd6-802d-59389a966d2e
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
The number of photons can be computed from $Q(t', Z)$ which is defined as the number of photons produced by a stellar population of one solar mass, of age $t'$, and metallicity $Z$, per unit of time. So, we have the relation
$\begin{equation}
\dot{N}(t) = \int_0^t \mathrm{SFR}(t - t') \, Q(t', Z(t - t')) \, \mathrm{d}t' \, ,
\end{equation}$
where $\mathrm{SFR}(t - t')$ is the instantaneous SFR at the moment of birth of the stellar population of current age $t'$ (in units of solar mass per unit of time), and $Z = Z(t - t')$ is defined as the metallicity at that moment. Because most of the contribution to the integral comes from young blue stars that die in the first $10 \ \mathrm{to} \ 100 \, \mathrm{Myr}$, it is possible to approximate
$\begin{align}
\mathrm{SFR}(t - t') &\approx \mathrm{SFR}(t) \, , \\
Z(t - t') &\approx Z(t) \, .
\end{align}$
So, we end up with the general form
$\begin{equation}
\eta = c \, \frac{\dot{N}}{\mathrm{SFR}} = c \, \int_0^t Q(t', Z) \, \mathrm{d}t'\, ,
\end{equation}$
The value of $Q$ can be calculated using
$\begin{equation}
Q(t', Z) = \int_{\lambda_1}^{\lambda_2} \frac{L_\lambda(t', Z)}{E_\lambda} \mathrm{d}\lambda = \int_{\lambda_1}^{\lambda_2} \frac{\lambda \, L_\lambda(t', Z)}{h \, c} \, \mathrm{d}\lambda \, ,
\end{equation}$
where $L_\lambda(t', Z)$ is the luminosity per unit of wavelength of a stellar population of one solar mass, age $t'$, and metallicity $Z$; and $E_\lambda = \lambda / (h \, c)$ is the energy of a photon of wavelength $\lambda$. So, integrating between the wavelength of interest, we get the number of photons produced per unit of time for a stellar population of the given characteristics.
The luminosity will not only depend on the age and metallicity of the population, but on the initial mass function (IMF)) too, so in principle for each IMF, $t'$, and $Z$ we have a function of luminosity versus $\lambda$.
Using the values from PopStar by [Mollá2009](https://doi.org/10.1111/j.1365-2966.2009.15160.x) we compute a table of $Q$ for six IMFs ([Salpeter1955](https://doi.org/10.1086/145971) in two mass ranges: $0.85\,\mathrm{M}_\odot$ to $120\,\mathrm{M}_\odot$ and $0.15\,\mathrm{M}_\odot$ to $100\,\mathrm{M}_\odot$, [Kroupa2001](https://doi.org/10.1046/j.1365-8711.2001.04022.x), [Ferrini1990](https://ui.adsabs.harvard.edu/abs/1990A%26A...231..391F), and [Chabrier2003](https://doi.org/10.1086/374879)), six metallicities (0.0001, 0.0004, 0.004, 0.008, 0.02, and 0.05) and for ages between $0.1\,\mathrm{Myr}$, and $15\,\mathrm{Gyr}$.
"""
╠═╡ =#
# ╔═╡ 35083c71-0a7c-4b97-94ef-4d06ecbd2ee8
begin
# Raw luminosity data from
# https://www.fractal-es.com/PopStar/#download (PopStar2009)
data_folders = readdir("./data/luminosity", join=true)
# Regex patterns to parse the filenames, IMF_mlow_mup_zXXXX_tXXXX
patterns = [
r"(?<=spneb_)(.*?)(?=_z)", # IMF_mlow_mup
r".+?(?=_)", # IMF
r"(?<=_)(.*?)(?=_)", # mlow
r"[^_]+$", # mup
r"(?<=z)(.*?)(?=_)", # metallicity
r"(?<=t)(.*)", # log(age)
]
# Wavelength range for the photodissociation of Hydrogen molecules
λ_range_d = (912.0u"Å", 1107.0u"Å")
# Wavelength range for the photoionization of Hydrogen atoms
λ_range_i = (0.0u"Å", 912.0u"Å")
# Unit conversion factor for the spectral energy distributions
u_sed = 3.82e33u"erg * s^-1 * Å^-1"
data_in_files = Vector{DataFrame}(undef, length(data_folders))
@inbounds for (i, dir) in pairs(data_folders)
files = readdir(dir, join=true)
IMF_mlow_mup = getfield.(match.(patterns[1], basename.(files)), :match)
IMF = getfield.(match.(patterns[2], IMF_mlow_mup), :match)
mlow = getfield.(match.(patterns[3], IMF_mlow_mup), :match)
mup = getfield.(match.(patterns[4], IMF_mlow_mup), :match)
Zmet = getfield.(match.(patterns[5], basename.(files)), :match)
ages = getfield.(match.(patterns[6], basename.(files)), :match)
Q_diss = Vector{Quantity}(undef, length(files))
Q_ion = Vector{Quantity}(undef, length(files))
@inbounds for (i, file) in pairs(files)
# Load data
data = readdlm(file)
df = identity.(DataFrame(data, [:λ, :Ls, :Lneb, :Ltot]))
# Set units
# Wavelength
df[!, 1] = df[!, 1] .* u"Å"
# Stellar spectral energy distributions per unit wavelength
df[!, 2] = df[!, 2] .* u_sed
# Nebular spectral energy distributions per unit wavelength
df[!, 3] = df[!, 3] .* u_sed
# Total spectral energy distributions per unit wavelength
df[!, 4] = df[!, 4] .* u_sed
# Spectral energy distribution integration
let
λ = @subset(df, λ_range_d[1] .< :λ .< λ_range_d[2])
integrand = λ[!, 1] .* λ[!, 2] ./ (Unitful.h * Unitful.c)
Q_diss[i] = trapz(λ[!, 1], integrand) |> u"s^-1"
end
let
λ = @subset(df, λ_range_i[1] .< :λ .< λ_range_i[2])
integrand = λ[!, 1] .* λ[!, 2] ./ (Unitful.h * Unitful.c)
Q_ion[i] = trapz(λ[!, 1], integrand) |> u"s^-1"
end
end
data_in_files[i] = identity.(
DataFrame(
:IMF => uppercase.(IMF), # Initial mass function
:mlow => parse.(Float64, mlow), # Min. mass of the IMF
:mup => parse.(Float64, mup), # Max. mass of the IMF
:Zmet => parse.(Float64, "0." .* Zmet), # Metallicities
:log_age => parse.(Float64, ages), # Stellar ages
:Q_diss => Q_diss, # Number of dissociating photons per unit time
:Q_ion => Q_ion, # Number of dissociating photons per unit time
)
)
end
Q_data = sort(vcat(data_in_files...), [:IMF, :mlow, :Zmet, :log_age])
# Separate the computed Q values by IMF
Salpeter1955A = @select(
@subset(Q_data, :IMF .== "SAL", :mlow .== 0.85),
$(Not([:IMF, :mlow, :mup])),
)
Salpeter1955B = @select(
@subset(Q_data, :IMF .== "SAL", :mlow .== 0.15),
$(Not([:IMF, :mlow, :mup])),
)
Ferrini1990 = @select(
@subset(Q_data, :IMF .== "FER"),
$(Not([:IMF, :mlow, :mup])),
)
Kroupa2001 = @select(
@subset(Q_data, :IMF .== "KRO"),
$(Not([:IMF, :mlow, :mup])),
)
Chabrier2003 = @select(
@subset(Q_data, :IMF .== "CHA"),
$(Not([:IMF, :mlow, :mup])),
)
Q_by_imf = Dict(
"Salpeter1955A" => Salpeter1955A,
"Salpeter1955B" => Salpeter1955B,
"Ferrini1990" => Ferrini1990,
"Kroupa2001" => Kroupa2001,
"Chabrier2003" => Chabrier2003,
)
Q_data
end
# ╔═╡ 76a10b7c-1135-49f1-a298-36c59bb94b37
# ╠═╡ skip_as_script = true
#=╠═╡
md"""
In what follows we will use the IMF by [Chabrier2003](https://doi.org/10.1086/374879)
"""
╠═╡ =#
# ╔═╡ 72794eb3-7f09-4445-906a-af9756dceebd
begin
const IMF = "Chabrier2003" # Initial mass function
const Q_df = Q_by_imf[IMF]
const Q_ages = unique(Q_df[!, :log_age]) # List of stellar ages
const Q_metals = unique(Q_df[!, :Zmet]) # List of metallicities
end;
# ╔═╡ b96de0fd-a65b-463a-9c91-2504b8427dba
# ╠═╡ skip_as_script = true
#=╠═╡
begin
aprox_test = @subset(Q_df, :Zmet .== 0.05)
max_age = round(
ustrip(u"Myr", exp10(aprox_test[!, :log_age][39]) * u"yr");
sigdigits=4,
)
Q_diss_quot = round(
sum(aprox_test[!, :Q_diss][1:39]) / sum(aprox_test[!, :Q_diss][40:end]);
sigdigits=4,
)
Q_ion_quot = round(
sum(aprox_test[!, :Q_diss][1:39]) / sum(aprox_test[!, :Q_diss][40:end]);
sigdigits=4,
)
println("The accumulated Q_diss for stars younger than $(max_age) Myr is $(Q_diss_quot) larger that the accumulated Q_diss produced by all the stars older than that.\n")
println("The accumulated Q_ion for stars younger than $(max_age) Myr is $(Q_ion_quot) larger that the accumulated Q_ion produced by all the stars older than that.")
end
╠═╡ =#
# ╔═╡ 1f190b07-164b-4ba9-86f8-edcf6e7ab3a9
##################################################################################
# Compute η_diss and η_ion
#
# age: Age [Myr]
# Z: Metallicity [dimensionless]
##################################################################################
function photodissociation_efficiency(age::Float64, Z::Float64)::NTuple{2,Float64}
# Allocate memory for η_diss and η_ion
η_diss = Matrix{Float64}(undef, length(Q_ages), length(Q_metals))
η_ion = Matrix{Float64}(undef, length(Q_ages), length(Q_metals))
@inbounds for (i, log_age) in pairs(Q_ages)
@inbounds for (j, Zmet) in pairs(Q_metals)
sub_df = @subset(Q_df, :Zmet .== Zmet, :log_age .<= log_age)
# Set the values of the axes, with an extra point,
# to integrate from age 0 onwards
ages = [0.0, exp10.(sub_df[!, :log_age])...] .* u"yr"
q_diss = sub_df[!, :Q_diss]
Q_diss = [q_diss[1], q_diss...]
η_diss[i, j] = uconvert(Unitful.NoUnits, trapz(ages, Q_diss) * c_diss)
q_ion = sub_df[!, :Q_ion]
Q_ion = [q_ion[1], q_ion...]
η_ion[i, j] = uconvert(Unitful.NoUnits, trapz(ages, Q_ion) * c_ion)
end
end
max_age = log10(age * 10^6)
ifunc_η_diss = linear_interpolation(