Skip to content

General fixes - #26

Merged
cdplagos merged 4 commits into
ICRAR:develfrom
christopherlovell:devel
Oct 20, 2026
Merged

cdplagos merged 4 commits into
ICRAR:develfrom
christopherlovell:devel

Conversation

@christopherlovell

@christopherlovell christopherlovell commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

PR contains three relatively minor fixes:

  • manual_integral: pass params, not &params, 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:

  • Add configurable stellar-feedback redshift normalization for the Lagos13 model.

Bug Fixes:

  • Correct manual integration callbacks so integrands receive their intended parameters.
  • Ensure fully molecular gas is assigned a molecular fraction of one despite floating-point rounding.
  • Use the galaxy redshift when applying the Lagos13 stellar-feedback redshift dependence.

Callers' integrands cast the context pointer straight to their props struct,
so passing &params (void**) made the GSL-failure fallback dereference garbage
and segfault.
@sourcery-ai

sourcery-ai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes 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 callback

sequenceDiagram
    participant Integrator as manual_integral
    participant Integrand as func_t
    Integrator->>Integrand: f(rx, params)
    Integrand-->>Integrator: integrand value
    Integrator->>Integrator: accumulate integral
Loading

Sequence diagram for redshift-dependent Lagos13 feedback velocity

sequenceDiagram
    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
Loading

Flow diagram for fully molecular gas clamping

flowchart 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]
Loading

File-Level Changes

Change Details Files
Correct the fallback numerical integration callback context.
  • Pass the original parameter pointer to the integrand instead of the address of the local pointer variable.
  • Prevent incorrect integral results that can violate star-formation invariants or suppress star formation.
src/star_formation.cpp
Handle fully molecular gas correctly at floating-point saturation.
  • Use an inclusive upper clamp when the molecular fraction rounds to 1.
  • Preserve positive fractions below 1 without requiring a strict upper-bound check.
src/star_formation.cpp
Implement redshift-dependent stellar-feedback velocity using configurable cosmic-time normalization.
  • Add and load redshift_norm, documenting and defaulting it to zero in sample configurations.
  • Compute vhot from the ratio of cosmic ages at the galaxy redshift and normalization redshift.
  • Restore v_sn as the feedback velocity at redshift_norm rather than using the parameter value as a redshift.
include/stellar_feedback.h
src/stellar_feedback.cpp
sample.cfg
sample_lagos23.cfg

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/star_formation.cpp
// 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){

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@cdplagos
cdplagos merged commit 167b4e9 into ICRAR:devel Oct 20, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants