Repository navigation
General fixes - #26
Conversation
Callers' integrands cast the context pointer straight to their props struct, so passing ¶ms (void**) made the GSL-failure fallback dereference garbage and segfault.
Small bug fixes
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes three numerical and physics issues: the manual integrator now passes callback parameters correctly, fully molecular gas is retained when floating-point rounding produces exactly one, and Lagos13 feedback velocity scales with the galaxy’s cosmic age relative to a configurable normalization redshift. Sequence diagram for corrected manual integration callbacksequenceDiagram
participant Integrator as manual_integral
participant Integrand as func_t
Integrator->>Integrand: f(rx, params)
Integrand-->>Integrator: integrand value
Integrator->>Integrator: accumulate integral
Sequence diagram for redshift-dependent Lagos13 feedback velocitysequenceDiagram
participant Galaxy
participant Feedback as StellarFeedback
participant Cosmology
Galaxy->>Feedback: outflow_rate(sfr, vsubh, vgal, z)
Feedback->>Cosmology: convert_redshift_to_age(z)
Cosmology-->>Feedback: t(z)
Feedback->>Cosmology: convert_redshift_to_age(redshift_norm)
Cosmology-->>Feedback: t(redshift_norm)
Feedback->>Feedback: vhot = v_sn * (t(z) / t(redshift_norm)) ^ redshift_power
Feedback-->>Galaxy: outflow rate
Flow diagram for fully molecular gas clampingflowchart TD
A["Compute fmol = rmol / (1 + rmol)"] --> B{fmol >= 1}
B -->|Yes| C[Return 1]
B -->|No| D{fmol > 0}
D -->|Yes| E[Return fmol]
D -->|No| F[Return 0]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/star_formation.cpp" line_range="386" />
<code_context>
+ // Avoid calculation errors. rmol/(1+rmol) rounds to exactly 1 once
+ // rmol >= 2^53, so the upper clamp must be inclusive or fully molecular
+ // gas would be assigned zero molecular fraction.
+ if(fmol >= 1){
return 1;
}
</code_context>
<issue_to_address>
**Fully molecular gas gets zero fraction**
When K13 or KMT09 produces a zero intermediate fraction, including `kmt09_fmol` returning zero at extreme gas surface density, `rmol` becomes positive infinity, so `fmol = rmol/(1+rmol)` evaluates to NaN, both comparisons fail, and the function returns 0 for fully molecular gas.
Handle positive-infinite `rmol` before evaluating the division and return 1.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: src/star_formation.cpp:386
| // Avoid calculation errors. rmol/(1+rmol) rounds to exactly 1 once | ||
| // rmol >= 2^53, so the upper clamp must be inclusive or fully molecular | ||
| // gas would be assigned zero molecular fraction. | ||
| if(fmol >= 1){ |
There was a problem hiding this comment.
🟡 Medium · Fully molecular gas gets zero fraction
When K13 or KMT09 produces a zero intermediate fraction, including kmt09_fmol returning zero at extreme gas surface density, rmol becomes positive infinity, so fmol = rmol/(1+rmol) evaluates to NaN, both comparisons fail, and the function returns 0 for fully molecular gas.
Handle positive-infinite rmol before evaluating the division and return 1.
Prompt for AI agents
In `src/star_formation.cpp` at line 386:
**Fully molecular gas gets zero fraction**
When K13 or KMT09 produces a zero intermediate fraction, including `kmt09_fmol` returning zero at extreme gas surface density, `rmol` becomes positive infinity, so `fmol = rmol/(1+rmol)` evaluates to NaN, both comparisons fail, and the function returns 0 for fully molecular gas.
Handle positive-infinite `rmol` before evaluating the division and return 1.
PR contains three relatively minor fixes:
manual_integral: pass params, not ¶ms, to the integrand. The fallback integrator handed the integrand the address of its own pointer argument, so it always returned ~0. For galaxies with stars this trips the psi > 0 invariant and aborts the run; for galaxies without, star formation is silently zeroed.
rmol/(1+rmol) rounds to exactly 1 once rmol >= 2^53, and fmol == 1.0 matched neither > 1 nor < 1, so fully molecular gas returned 0. Fix makes the upper clamp inclusive.
convert_redshift_to_age(parameters.redshift_power) was called with the parameter rather than the galaxy's redshift, making v_hot a constant. Fixed so v_hot = v_sn [t(z)/t(redshift_norm)]^rp with a new stellar_feedback.redshift_norm (default 0), so v_sn keeps its z = 0 calibration meaning.
Summary by Sourcery
Fix integration parameter handling, molecular-gas fraction clamping, and redshift-dependent stellar feedback.
New Features:
Bug Fixes: