Jet review fixes: frozen Jet, validated amplitude replacement, test selector
Jet is a frozen dataclass; with_amplitude returns a validated copy, so region/field/profile cannot drift from the cached per-link shapes and amplitude cannot bypass validation. CurvedLinkSoA.set_jet_amplitude and Simulation.set_jet_amplitude replace the Jet (Simulation also updates the registered list so later geometry syncs keep the amplitude). Reject non-finite hits; document edge rule (|s|<1 exclusive, radial/along bounds inclusive). Fix the clipped-q test selector to receiver (9,5) dir 8, as in test_surface_actuation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
932702f779
commit
b1cd555b0f
+18
-3
@@ -74,8 +74,8 @@ def test_selection_uses_true_hit_not_clipped_q():
|
||||
t = (6-math.sqrt(36-8*(9-2.999**2)))/4
|
||||
angle = math.atan2(t, 3-t)
|
||||
_, cl, _, _, hits = scene()
|
||||
row = np.flatnonzero((cl.fluid_idx == 5*12 + 9) & np.isclose(cl.q, .01))
|
||||
assert len(row) == 1
|
||||
row = np.flatnonzero((cl.fluid_idx == 5*12 + 9) & (cl.dir == 8))
|
||||
assert len(row) == 1 and np.isclose(cl.q[row[0]], .01)
|
||||
clipped = np.array([9., 5.]) + .01*np.array([-1., 1.])
|
||||
jet = Jet(Sector(CENTER, angle, 1e-4, RADIUS + .1), Radial(CENTER))
|
||||
_, jet_id = jet_link_shapes([jet], hits)
|
||||
@@ -120,7 +120,22 @@ def test_amplitude_update_reuses_cached_shapes():
|
||||
assert np.array_equal(cl.aperture, ids >= 0)
|
||||
with pytest.raises(ValueError):
|
||||
cl.set_jet_amplitude(0, 1.5)
|
||||
assert jet.amplitude == -2e-3
|
||||
assert cl.jets[0].amplitude == -2e-3 and jet.amplitude == 1e-3 # registered Jet untouched
|
||||
np.testing.assert_allclose(cl.surface_velocity, -2*before, rtol=1e-6, atol=0)
|
||||
|
||||
|
||||
def test_jet_definition_is_immutable_and_amplitude_validated():
|
||||
jet = Jet(Sector(CENTER, 0., .5, 4.), Radial(CENTER), "parabolic", 1e-3)
|
||||
for name, value in (("field", Parallel(0.)), ("region", Tube(CENTER, 0., 1., 1.)),
|
||||
("profile", "uniform"), ("amplitude", float("nan"))):
|
||||
with pytest.raises(AttributeError):
|
||||
setattr(jet, name, value)
|
||||
for bad in (float("nan"), float("inf"), 1.0):
|
||||
with pytest.raises(ValueError):
|
||||
jet.with_amplitude(bad)
|
||||
assert jet.with_amplitude(-1e-3).field is jet.field and jet.amplitude == 1e-3
|
||||
with pytest.raises(ValueError, match="finite"):
|
||||
jet_link_shapes([jet], [[np.nan, 5.]])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("spec", [SurfaceActuation(0., .6, .002), SurfaceActuation(2., 1.1, -.003)])
|
||||
|
||||
Reference in New Issue
Block a user