Repository navigation
Write polar CSV coefficients at 16 significant digits instead of 4 decimals - #369
Conversation
write_polar_csv, write_polar_matrix_csv and write_aero_matrix rounded every coefficient to 4 decimals, which on a Cd near 0.009 wipes out the response to a small flap deflection. All three, and the NeuralFoilResult writer that already used %.16g, now format rows through one csv_fields. Closes #362 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Coefficients go out at %.4g, which still resolves a 7e-6 Cd change on a 0.009 base. Angles stay at %.16g so a grid knot such as 100.25 deg is not rounded onto a neighbour, which assemble_polar_matrix matches exactly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1-Bort-1
left a comment
There was a problem hiding this comment.
Independent review (advisory)
Verdict: APPROVE WITH COMMENTS · 1 inline, 0 off the diff
Good
- One
csv_fieldshelper replaces three copies of the row-join. I checked with a grep: no%.4fordigits=4formatting is left insrc/. - Values below 1e-4 come out of
%.4gin exponent form (1.234e-05). Both readers parse the coefficient columns withparse(Float64, …), which reads that fine (polars.jl:96,yaml_geometry.jldata loop). - Angle columns stay at
%.16g, soassemble_polar_matrix's exactuniquestill rebuilds the (α, δ) grid. The new testset checks this withalphas == alpha_range && deltas == delta_range. - The kite-geometry assertion is not weakened. For the values it checks, an elementwise
rtol=5e-4is tighter than the old absolute5e-5, and the stale 'rounded to 4 decimals' comment is gone. - The PR had a bug-first test: the card reports the new testset failing 3 of 6 on unchanged code. The
write_aero_matrixlabels were left at 1 decimal on purpose, because the reader's regex takes no exponent, and the card says so.
Not good
CHANGELOG.md:38— The entry says all three writers used to write 4 decimals. TheNeuralFoilResultmethod ofwrite_polar_csvwrote 16 significant digits and now writes 4, so for its users this is a precision cut the changelog does not mention.- The
NeuralFoilResultwrite_polar_csvgoes from%.16gto%.4gcoefficients, which loses precision. The card attributes this to the thread, but no test covers that writer, and the changelog only speaks of '4 decimals → 4 significant digits', which is wrong for this method. - The testset name 'keep a Cd deflection response below 1e-4' says 'below 1e-4' where it means a response smaller than 1e-4 survives the round-trip; 'survives' would read clearer.
csv_fieldsis defined inairfoil_io.jlbut used fromairfoil_solvers/common.jlandpolar_export.jl, so it works only because of include order and nothing states that coupling.- The rtol of
5e-4is exactly the worst-case%.4grounding error (half a unit in the 4th digit at mantissa 1.000). The test has no margin and would flake if a value landed on that edge. - Tables already written keep their 4-decimal values with no warning. The card says this openly and the changelog says to regenerate, so it is acceptable, but the
test/generated/cache key still ignores the file format.
claude, rubric CLEAN_CODE.md. A different lab from the implementer
on purpose: a reviewer sharing its blind spots would not flag its mistakes.
|
|
||
| ### Fixed | ||
|
|
||
| - `write_polar_csv`, `write_polar_matrix_csv` and `write_aero_matrix` write coefficients |
There was a problem hiding this comment.
MINOR: The entry says all three writers used to write 4 decimals. The NeuralFoilResult method of write_polar_csv wrote 16 significant digits and now writes 4, so for its users this is a precision cut the changelog does not mention.
There was a problem hiding this comment.
Moot since 7b826f7: every writer is back at 16 significant digits, so the NeuralFoilResult method writes what it always did and the changelog's '4 decimals → 16 significant digits' holds for the two writers it names. The round-trip test still covers the NeuralFoilResult writer.
The changelog now says that writer went from 16 significant digits to 4, and the testset name says what survives the round-trip. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Every column now goes out through the one-line %.16g csv_fields, so the tables round-trip exactly and the tests compare with plain ≈. The NeuralFoilResult writer keeps the 16 digits it always had. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Local full suite: PASS (6 min, Julia 1.13.0, one cell of the matrix) |
TL;DR
write_polar_csv,write_polar_matrix_csvandwrite_aero_matrixnow write every column at 16 significant digits, where they used to round coefficients to 4 decimals. On a kite sectionCd ≈ 0.009, so 4 decimals wiped out the drag response to a small flap deflection, and everyPOLAR_MATRICESwing built byobj_to_yamlhad a zero or step-quantised∂Cd/∂δ.What was wrong
The two
AirfoilAerotable writers used@sprintf("%.4f"), so the1e-4rounding step was about 1% ofCd.write_aero_matrix(create_2d_polars) had the same bug throughround(v; digits=4). The issue's own measurement shows the scale. On a table regenerated fromram_air_kite_body.obj(n_sections=4, α and δ over ±1°),max |cd_interp(α, 1°) − cd_interp(α, 0°)|now ranges from 2.8e-5 to 6.3e-5 across the 20 panels. The issue measured exactly0.0on the outboard panels.What changed
csv_fields(values)formats every row at%.16g. TheNeuralFoilResultwrite_polar_csvinairfoil_io.jlalready wrote%.16gand now calls the same helper, so there is one row-join where there were three. A row now reads0,-1,0.08439307659864426,0.008839144371449947,0.004150335676968098.assemble_polar_matrixneeds because it rebuilds the(α, δ)grid with an exactunique.%.16galso writesrad2deg(deg2rad(3))as3.write_aero_matrixkeeps itsδ=…°/α=…°labels at 1 decimal, becauseread_aero_matrix's regex does not accept an exponent. Only its coefficient columns changed.Tables already written are not rewritten; regenerate them to pick this up. Nothing errors if they stay as they are. No tracked data file comes from these writers. The
test/generated/fixture cache is gitignored, and its key does not include the file format, so a local cache keeps its 4-decimal tables until it is deleted.Where I would push back
An earlier round on this branch wrote coefficients at 4 significant digits, as asked on the thread. That cost a two-argument formatter (angles have to stay at 16 digits for the exact grid rebuild), a
rtol=5e-4on every round-trip test, and a precision cut in theNeuralFoilResultwriter. The files at 16 digits are about 2.5× larger, roughly 35 KB instead of 14 KB for a 50 α × 7 δ section, and none of them are committed. So this goes back to 16 digits for every column.Tests
a Cd deflection response under 1e-4 survives the polar CSV round-trip(test/airfoil_aero/test_airfoil_aero.jl). It writes aCdwith a2e-5/degree deflection slope through all four writers (bothwrite_polar_csvmethods,write_polar_matrix_csv,write_aero_matrix). It reads each back throughload_polar_dataorread_aero_matrix, requires≈on the coefficients and exact equality on the angle knots.test/ram_geometry/test_kite_geometry.jl: thewrite_aero_matrixround-trip allowed an absolute5e-5"because coefficients are rounded to 4 decimals". It is now plain≈.Verification
[0.0082, 0.0092, …]for[0.00824, 0.00924, …], the labelled matrix likewise, and thePOLAR_MATRICESmatrices failed as well.test/airfoil_aero/test_airfoil_aero.jlandtest/ram_geometry/test_kite_geometry.jlhave no failures. The one Broken in the kite file is the existing@test_skip false.test/generated/.test/obj_adapter/test_obj_adapter.jl51/51,test/body_aerodynamics/test_results.jl30/30,test/solver/test_forwarddiff.jl10/10,test/wake/test_wake.jl3/3. Not rerun on 7b826f7.test/plotting/test_plotting.jl: not run locally, because thetestenvironment has no manifest and no CairoMakie.runtests.jlincludes it on Linux CI. Itsdeflected[2] != stored[2]guard on panel 3 rests on the 4.0e-5 difference above.bin/reuse_lint.main(8754b6d,git merge-tree); not synced, since nothing there conflicts or is needed here.test/generated/cache made before this change keeps its 4-decimal tables until it is deleted.Scope
+55 / −8 across 7 files.
src/is a one-line helper with its docstring, and four call sites. The rest is the new testset, the tightened kite assertion, a changelog line and a docs index entry.Closes #362 · task
VortexStepMethod.jl-362