Skip to content

Commit fd62507

Browse files
committed
Added :molecular_stellar_fraction and distribute the argument icGen up the stack of functions as a default kwarg
1 parent 2f6c9b8 commit fd62507

File tree

8 files changed

+205
-60
lines changed

8 files changed

+205
-60
lines changed

src/analysis/compute_quantities/aggregators.jl

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,29 @@
33
####################################################################################################
44

55
"""
6-
scatterQty(data_dict::Dict, quantity::Symbol)::Vector{<:Number}
6+
scatterQty(
7+
data_dict::Dict,
8+
quantity::Symbol;
9+
<keyword arguments>
10+
)::Vector{<:Number}
711
812
Compute `quantity` for each cell/particle in `data_dict`.
913
1014
# Arguments
1115
1216
- `data_dict::Dict`: Data dictionary (see [`makeDataDict`](@ref) for the canonical description).
1317
- `quantity::Symbol`: Target quantity. See [`plotParams`](@ref) for possibilities; only quantities well defined for each cell/particle individually are possible.
18+
- `icGen::Function=initialConditionFunction`: Function that generates the initial condition function for the :ode components. It must have the signature `icGen(data_dict::Dict, component::Symbol)::Union{Function,Nothing}`. This keyword argument is only relevant if `quantity` depends on one of the :ode components (e.g., `:ode_atomic_fraction`).
1419
1520
# Returns
1621
1722
- The values of `quantity` for every cell/particle.
1823
"""
19-
function scatterQty(data_dict::Dict, quantity::Symbol)::Vector{<:Number}
24+
function scatterQty(
25+
data_dict::Dict,
26+
quantity::Symbol;
27+
icGen::Function=initialConditionFunction,
28+
)::Vector{<:Number}
2029

2130
#####################
2231
# Derived quantities
@@ -28,27 +37,27 @@ function scatterQty(data_dict::Dict, quantity::Symbol)::Vector{<:Number}
2837

2938
if magnitude == :mass
3039

31-
scatter_qty = computeMass(data_dict, component)
40+
scatter_qty = computeMass(data_dict, component; icGen)
3241

3342
elseif magnitude == :mass_density
3443

35-
scatter_qty = computeMassDensity(data_dict, component)
44+
scatter_qty = computeMassDensity(data_dict, component; icGen)
3645

3746
elseif magnitude == :number_density
3847

39-
scatter_qty = computeNumberDensity(data_dict, component)
48+
scatter_qty = computeNumberDensity(data_dict, component; icGen)
4049

4150
elseif magnitude == :number
4251

43-
scatter_qty = computeNumber(data_dict, component)
52+
scatter_qty = computeNumber(data_dict, component; icGen)
4453

4554
elseif magnitude == :fraction
4655

47-
scatter_qty = computeFraction(data_dict, component)
56+
scatter_qty = computeFraction(data_dict, component; icGen)
4857

4958
elseif magnitude == :eff
5059

51-
scatter_qty = computeEfficiencyFF(data_dict, component)
60+
scatter_qty = computeEfficiencyFF(data_dict, component; icGen)
5261

5362
elseif magnitude == :specific_z_angular_momentum
5463

@@ -94,19 +103,19 @@ function scatterQty(data_dict::Dict, quantity::Symbol)::Vector{<:Number}
94103

95104
elseif magnitude == :kinetic_energy
96105

97-
scatter_qty = computeKineticEnergy(data_dict, component)
106+
scatter_qty = computeKineticEnergy(data_dict, component; icGen)
98107

99108
elseif magnitude == :potential_energy
100109

101-
scatter_qty = computePotentialEnergy(data_dict, component)
110+
scatter_qty = computePotentialEnergy(data_dict, component; icGen)
102111

103112
elseif magnitude == :total_energy
104113

105-
scatter_qty = computeTotalEnergy(data_dict, component)
114+
scatter_qty = computeTotalEnergy(data_dict, component; icGen)
106115

107116
elseif magnitude == :depletion_time
108117

109-
scatter_qty = computeDepletionTime(data_dict, component)
118+
scatter_qty = computeDepletionTime(data_dict, component; icGen)
110119

111120
elseif magnitude == :xy_distance
112121

@@ -256,7 +265,7 @@ function scatterQty(data_dict::Dict, quantity::Symbol)::Vector{<:Number}
256265

257266
elseif quantity == :ode_metallicity
258267

259-
scatter_qty = computeFraction(data_dict, :ode_metals) ./ SOLAR_METALLICITY
268+
scatter_qty = computeFraction(data_dict, :ode_metals; icGen) ./ SOLAR_METALLICITY
260269

261270
elseif quantity GAS_METALS_MASS
262271

@@ -311,6 +320,7 @@ Compute `quantity` for the whole system of cell/particles in `data_dict`.
311320
- `data_dict::Dict`: Data dictionary (see [`makeDataDict`](@ref) for the canonical description).
312321
- `quantity::Symbol`: Target quantity. See [`plotParams`](@ref) for possibilities.
313322
- `agg_function::Union{Function,Symbol}=:default`: If `quantity` is one the the listed symbols in [`DERIVED_QTY`](@ref), [`SFM_STELLAR_QTY`](@ref) or [`SFM_GAS_QTY`](@ref), you can pass an `agg_function` to accumulate the values given by [`scatterQty`](@ref). If `agg_function` is left as `:default` [`integrateQty`](@ref) will try to compute the most reasonable global value for `quantity`.
323+
- `icGen::Function=initialConditionFunction`: Function that generates the initial condition function for the :ode components. It must have the signature `icGen(data_dict::Dict, component::Symbol)::Union{Function,Nothing}`. This keyword argument is only relevant if `quantity` depends on one of the :ode components (e.g., `:ode_atomic_fraction`).
314324
315325
# Returns
316326
@@ -320,6 +330,7 @@ function integrateQty(
320330
data_dict::Dict,
321331
quantity::Symbol;
322332
agg_function::Union{Function,Symbol}=:default,
333+
icGen::Function=initialConditionFunction,
323334
)::Number
324335

325336
if agg_function == :default
@@ -334,7 +345,7 @@ function integrateQty(
334345

335346
if magnitude == :mass
336347

337-
integrated_qty = sum(computeMass(data_dict, component); init=0.0u"Msun")
348+
integrated_qty = sum(computeMass(data_dict, component; icGen); init=0.0u"Msun")
338349

339350
elseif magnitude == :number
340351

@@ -360,7 +371,7 @@ function integrateQty(
360371
type = :gas
361372
end
362373

363-
comp_mass = sum(computeMass(data_dict, component); init=0.0u"Msun")
374+
comp_mass = sum(computeMass(data_dict, component; icGen); init=0.0u"Msun")
364375
ref_mass = sum(computeMass(data_dict, type); init=0.0u"Msun")
365376

366377
if iszero(ref_mass)
@@ -371,7 +382,7 @@ function integrateQty(
371382

372383
elseif magnitude == :clumping_factor
373384

374-
integrated_qty = computeClumpingFactor(data_dict, component)
385+
integrated_qty = computeClumpingFactor(data_dict, component; icGen)
375386

376387
elseif magnitude == :specific_z_angular_momentum
377388

@@ -380,7 +391,7 @@ function integrateQty(
380391
init=0.0u"Msun * pc^2 * yr^-1",
381392
)
382393

383-
M = sum(computeMass(data_dict, component); init=0.0u"Msun")
394+
M = sum(computeMass(data_dict, component; icGen); init=0.0u"Msun")
384395

385396
integrated_qty = Lz / M
386397

@@ -397,11 +408,14 @@ function integrateQty(
397408

398409
elseif magnitude == :potential_energy
399410

400-
integrated_qty = sum(computePotentialEnergy(data_dict, component); init=0.0u"erg")
411+
integrated_qty = sum(
412+
computePotentialEnergy(data_dict, component; icGen);
413+
init=0.0u"erg",
414+
)
401415

402416
elseif magnitude == :depletion_time
403417

404-
M = sum(computeMass(data_dict, component); init=0.0u"Msun")
418+
M = sum(computeMass(data_dict, component; icGen); init=0.0u"Msun")
405419
cp_type = plotParams(quantity).cp_type
406420

407421
if cp_type == :stellar
@@ -563,6 +577,19 @@ function integrateQty(
563577

564578
integrated_qty = 1.0 / AGE_RESOLUTION
565579

580+
elseif quantity == :molecular_stellar_fraction
581+
582+
m_H2 = integrateQty(data_dict, :ode_molecular_stellar_mass)
583+
m_star = integrateQty(data_dict, :stellar_mass)
584+
585+
m_tot = m_H2 + m_star
586+
587+
if iszero(m_tot)
588+
integrated_qty = NaN
589+
else
590+
integrated_qty = m_H2 / m_tot
591+
end
592+
566593
##################
567594
# Time quantities
568595
##################
@@ -619,7 +646,7 @@ function integrateQty(
619646

620647
elseif quantity == :ode_metallicity
621648

622-
Mz = sum(computeMass(data_dict, :ode_metals); init=0.0u"Msun")
649+
Mz = sum(computeMass(data_dict, :ode_metals; icGen); init=0.0u"Msun")
623650
Mg = sum(computeMass(data_dict, :gas); init=0.0u"Msun")
624651

625652
if iszero(Mg)

src/analysis/compute_quantities/energies.jl

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ end
121121
###################
122122

123123
"""
124-
computeKineticEnergy(data_dict::Dict, component::Symbol)::Vector{<:Unitful.Energy}
124+
computeKineticEnergy(
125+
data_dict::Dict,
126+
component::Symbol;
127+
<keyword arguments>
128+
)::Vector{<:Unitful.Energy}
125129
126130
Compute the kinetic energy.
127131
@@ -147,12 +151,17 @@ Compute the kinetic energy.
147151
+ If `component` ∈ [:ode_molecular, :ode_stellar, :ode_molecular_stellar]:
148152
* `:gas` => ["VEL ", "MASS", "FRAC", "RHO "]
149153
- `component::Symbol`: Target component. It can only be one of the elements of [`COMPONENTS`](@ref).
154+
- `icGen::Function=initialConditionFunction`: Function that generates the initial condition function for the :ode components. It must have the signature `icGen(data_dict::Dict, component::Symbol)::Union{Function,Nothing}`. This keyword argument is only relevant if `component` is one of the :ode components (e.g., `:ode_atomic`).
150155
151156
# Returns
152157
153158
- The kinetic energy of each cell/particle.
154159
"""
155-
function computeKineticEnergy(data_dict::Dict, component::Symbol)::Vector{<:Unitful.Energy}
160+
function computeKineticEnergy(
161+
data_dict::Dict,
162+
component::Symbol;
163+
icGen::Function=initialConditionFunction,
164+
)::Vector{<:Unitful.Energy}
156165

157166
if component COMPONENTS
158167
throw(ArgumentError("computeKineticEnergy: `component` can only be one of the elements \
@@ -167,15 +176,19 @@ function computeKineticEnergy(data_dict::Dict, component::Symbol)::Vector{<:Unit
167176
type = :gas
168177
end
169178

170-
masses = computeMass(data_dict, component)
179+
masses = computeMass(data_dict, component; icGen)
171180
velocities = data_dict[type]["VEL "]
172181

173182
return computeKineticEnergy(masses, velocities)
174183

175184
end
176185

177186
"""
178-
computePotentialEnergy(data_dict::Dict, component::Symbol)::Vector{<:Unitful.Energy}
187+
computePotentialEnergy(
188+
data_dict::Dict,
189+
component::Symbol;
190+
<keyword arguments>
191+
)::Vector{<:Unitful.Energy}
179192
180193
Compute the gravitational potencial energy.
181194
@@ -201,12 +214,17 @@ Compute the gravitational potencial energy.
201214
+ If `component` ∈ [:ode_molecular, :ode_stellar, :ode_molecular_stellar]:
202215
* `:gas` => ["POT ", "MASS", "FRAC", "RHO "]
203216
- `component::Symbol`: Target component. It can only be one of the elements of [`COMPONENTS`](@ref).
217+
- `icGen::Function=initialConditionFunction`: Function that generates the initial condition function for the :ode components. It must have the signature `icGen(data_dict::Dict, component::Symbol)::Union{Function,Nothing}`. This keyword argument is only relevant if `component` is one of the :ode components (e.g., `:ode_atomic`).
204218
205219
# Returns
206220
207221
- The gravitational potencial energy of each cell/particle.
208222
"""
209-
function computePotentialEnergy(data_dict::Dict, component::Symbol)::Vector{<:Unitful.Energy}
223+
function computePotentialEnergy(
224+
data_dict::Dict,
225+
component::Symbol;
226+
icGen::Function=initialConditionFunction,
227+
)::Vector{<:Unitful.Energy}
210228

211229
if component COMPONENTS
212230
throw(ArgumentError("computePotentialEnergy: `component` can only be one of the elements \
@@ -221,7 +239,7 @@ function computePotentialEnergy(data_dict::Dict, component::Symbol)::Vector{<:Un
221239
type = :gas
222240
end
223241

224-
masses = computeMass(data_dict, component)
242+
masses = computeMass(data_dict, component; icGen)
225243
potential = data_dict[type]["POT "]
226244

227245
return computePotentialEnergy(masses, potential)
@@ -230,7 +248,11 @@ function computePotentialEnergy(data_dict::Dict, component::Symbol)::Vector{<:Un
230248
end
231249

232250
"""
233-
computeTotalEnergy(data_dict::Dict, component::Symbol)::Vector{<:Unitful.Energy}
251+
computeTotalEnergy(
252+
data_dict::Dict,
253+
component::Symbol;
254+
<keyword arguments>
255+
)::Vector{<:Unitful.Energy}
234256
235257
Compute the total energy (kinetic + potential).
236258
@@ -256,15 +278,20 @@ Compute the total energy (kinetic + potential).
256278
+ If `component` ∈ [:ode_molecular, :ode_stellar, :ode_molecular_stellar]:
257279
* `:gas` => ["VEL ", "POT ", "MASS", "FRAC", "RHO "]
258280
- `component::Symbol`: Target component. It can only be one of the elements of [`COMPONENTS`](@ref).
281+
- `icGen::Function=initialConditionFunction`: Function that generates the initial condition function for the :ode components. It must have the signature `icGen(data_dict::Dict, component::Symbol)::Union{Function,Nothing}`. This keyword argument is only relevant if `component` is one of the :ode components (e.g., `:ode_atomic`).
259282
260283
# Returns
261284
262285
- The total energy of each cell/particle.
263286
"""
264-
function computeTotalEnergy(data_dict::Dict, component::Symbol)::Vector{<:Unitful.Energy}
287+
function computeTotalEnergy(
288+
data_dict::Dict,
289+
component::Symbol;
290+
icGen::Function=initialConditionFunction,
291+
)::Vector{<:Unitful.Energy}
265292

266-
Ep = computePotentialEnergy(data_dict, component)
267-
Ek = computeKineticEnergy(data_dict, component)
293+
Ep = computePotentialEnergy(data_dict, component; icGen)
294+
Ek = computeKineticEnergy(data_dict, component; icGen)
268295

269296
if any(isempty, [Ek, Ep])
270297

0 commit comments

Comments
 (0)