Repository navigation
Conversation
compute_tke_spectrum only assigned the domain lengths lx, ly, lz when length was None, so passing an explicit length raised UnboundLocalError at the first fftfreq call. Use the given length (defaulting to 2*pi) for all three axes. Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
CODEOWNERS review mapCurrent for commit ⏳ @mnabian — 1 file(s)
⏳ @peterdsharpe — 1 file(s)
No CODEOWNER
Comment |
|
[Low impact] The change is limited to the optional domain-length path of one CFD metric. The binned wavenumber axis should respect the supplied domain length before merging. Findings
SummaryFixes
Reviews (1) · Last reviewed commit: "Fix UnboundLocalError in compute_tke_spe..." · Reviewed by Greptile |
| if length is None: | ||
| lx, ly, lz = 2 * np.pi, 2 * np.pi, 2 * np.pi | ||
| length = 2 * np.pi | ||
| lx, ly, lz = length, length, length |
There was a problem hiding this comment.
Binned axis ignores domain size
Passing a different length now changes mk, but the returned wave_numbers still uses the fixed spacing 2 * np.pi. Doubling length halves the raw wavenumbers but leaves the binned spectrum’s axis unchanged. Users plotting wave_numbers against tke_spectrum therefore get an axis that ignores their domain length.
Make the binned axis scale with length, and check it in the new test.
Bug
compute_tke_spectrum(field, length=None)(physicsnemo/metrics/cae/cfd.py) only sets the domain lengths whenlengthis omitted:so passing the documented
lengthargument crashes a few lines later atkx = np.fft.fftfreq(nx, lx / nx):The existing test only calls it with the default, so this went unnoticed.
Fix
Default
lengthto2 * np.piand always setlx = ly = lz = length. Output withoutlengthis unchanged.Tests
test_compute_tke_spectrum_lengthintest/metrics/test_metrics_cfd.pychecks thatlength=2πreproduces the default output exactly and that wavenumbers scale with1 / length(length=1.0→2π ×the default). It fails onmainwith theUnboundLocalErrorand passes with the fix;test/metrics/test_metrics_cfd.pypasses locally (CPU, macOS).Checklist