Skip to content

smart_integrate() clips Piecewise integrals to their breakpoints #107

Description

@BenWibking

smart_integrate() clips Piecewise integrals to their breakpoints

Summary

smart_integrate() replaces the caller's integration interval with the minimum and
maximum Piecewise breakpoints. A Piecewise expression with one breakpoint therefore
gets an empty interval and always integrates to zero.

Explanation

After get_bounds() finds discontinuities, lines 190-194 of
src/jaff/common/_integrators.py use those points as new integration limits instead
of using them only as hints to scipy.integrate.quad.

This minimal reproduction returns 0.0, although the exact integral is 3.0:

import sympy as sp

from jaff.common._integrators import smart_integrate

x = sp.Symbol("x")
expr = sp.Piecewise((1, x < 1), (2, True))
assert smart_integrate(expr, x, (0, 2)) == 3.0

The same helper is used to partition radiation source terms across bands, so a
Piecewise dRad can silently produce zero or omit the portions outside the outermost
breakpoints.

Proposed patch

Keep a, b = t_low, t_high for the entire requested interval. Treat values returned
by get_bounds() only as internal quad(..., points=...) breakpoints after filtering
them with a < point < b. Add a regression test for both a single-breakpoint
Piecewise expression and a multi-breakpoint expression whose requested bounds extend
beyond the first and last breakpoint.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-code-auditIssues found by AI code audit

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions